|
16 | 16 | from .gitutils import ( # noqa E402 |
17 | 17 | MissingRemote, |
18 | 18 | OriginalBranch, |
| 19 | + ensure_repository_is_up_to_date, |
19 | 20 | get_git, |
20 | 21 | get_local_ref, |
21 | 22 | git_recent_tags, |
22 | 23 | has_local, |
23 | 24 | has_merge_conflict, |
24 | 25 | origin, |
25 | 26 | print_merge_details, |
| 27 | + show_most_recent_change, |
26 | 28 | ) |
27 | 29 |
|
28 | 30 | from .sh_verbose import ShVerbose # noqa E402 |
@@ -304,22 +306,44 @@ def inner(text, bold=False): |
304 | 306 | def main(): |
305 | 307 | parser = argparse.ArgumentParser(description='Rebuild the deploy branch for an environment') |
306 | 308 | parser.add_argument("config_path", help="Path to the YAML configuration file") |
| 309 | + remote_repo_group = parser.add_argument_group("remote repo") |
| 310 | + remote_repo_group.add_argument("--remote-url", help="Remote url to clone repository from") |
| 311 | + remote_repo_group.add_argument("--repo-root", help="Path where repository is checked out") |
| 312 | + remote_repo_group.add_argument("--repo-filepath", help="Relative path to YAML configuration file") |
307 | 313 | parser.add_argument("actions", nargs="*") |
308 | 314 | parser.add_argument("-p", "--path", default=".", help="Path to the repository") |
309 | 315 | parser.add_argument("-v", "--verbose", action="store_true") |
310 | 316 | parser.add_argument("--push", action="store_true", help="Push the changes to remote git repository.") |
311 | 317 | args = parser.parse_args() |
312 | 318 |
|
313 | 319 | git = get_git() |
| 320 | + |
| 321 | + print(args.remote_url) |
| 322 | + |
| 323 | + config_path = args.config_path |
| 324 | + remote_repo_args = [args.remote_url, args.repo_root, args.repo_filepath] |
| 325 | + if any(remote_repo_args) and not all(remote_repo_args): |
| 326 | + arg_names = [action.option_strings[0] for action in |
| 327 | + remote_repo_group._group_actions] |
| 328 | + print( |
| 329 | + red(f"All of the following arguments are required to use a remote " |
| 330 | + f"repository: {arg_names}")) |
| 331 | + exit(1) |
| 332 | + |
| 333 | + if args.remote_url and args.repo_root and args.repo_filepath: |
| 334 | + ensure_repository_is_up_to_date(git, args.remote_url, args.repo_root) |
| 335 | + show_most_recent_change(git, args.repo_root, args.repo_filepath) |
| 336 | + config_path = f"{args.repo_root}/{args.repo_filepath}" |
| 337 | + |
314 | 338 | print("Fetching master") |
315 | 339 | git.fetch("origin", "master") |
316 | 340 | if args.push: |
317 | 341 | print("Checking branch config for modifications") |
318 | | - if git.diff("origin/master", "--", args.config_path): |
319 | | - print(red("'{}' on this branch different from the one on master".format(args.config_path))) |
| 342 | + if git.diff("origin/master", "--", config_path): |
| 343 | + print(red("'{}' on this branch different from the one on master".format(config_path))) |
320 | 344 | exit(1) |
321 | 345 |
|
322 | | - with open(args.config_path) as config_yaml: |
| 346 | + with open(config_path) as config_yaml: |
323 | 347 | config = yaml.safe_load(config_yaml) |
324 | 348 |
|
325 | 349 | code_root = os.path.abspath(args.path) |
|
0 commit comments