From 53f10541c0631792f85a87c9fe6408accebff91e Mon Sep 17 00:00:00 2001 From: Hans Ulrich Niedermann Date: Mon, 9 Aug 2010 13:22:10 +0200 Subject: Add initial-merge --dry-run argument --- src/pyfedpkg/initial_merge.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/pyfedpkg/initial_merge.py b/src/pyfedpkg/initial_merge.py index 6f774bc..7350e8a 100755 --- a/src/pyfedpkg/initial_merge.py +++ b/src/pyfedpkg/initial_merge.py @@ -114,8 +114,9 @@ class Filter(object): and call do_initial_merge() for them. """ - def __init__(self, repo): + def __init__(self, repo, dry_run=False): self.repo = repo + self.dry_run = dry_run self.__reset() def __reset(self): @@ -127,13 +128,15 @@ class Filter(object): pyfedpkg.switch_branch(into.localbranch, self.repo.working_tree_dir) log.info("Merging %s into %s", repr([ x.origbranch for x in to_merge]), repr(into.localbranch)) - self.repo.git.merge('-m', 'Initial peudo merge for dist-git setup', - '-s', 'ours', - *[x.origbranch for x in to_merge]) + if not self.dry_run: + self.repo.git.merge('-m', 'Initial peudo merge for dist-git setup', + '-s', 'ours', + *[x.origbranch for x in to_merge]) for t in to_merge: pyfedpkg.switch_branch(t.localbranch, self.repo.working_tree_dir) log.info("Merging %s into %s", repr(into.localbranch), repr(t.localbranch)) - self.repo.git.merge(into.localbranch) + if not self.dry_run: + self.repo.git.merge(into.localbranch) pyfedpkg.switch_branch(into.localbranch, self.repo.working_tree_dir) def flush(self): @@ -161,7 +164,7 @@ class Filter(object): self.branch_list = [item] -def handle_repo(repo): +def handle_repo(repo, dry_run=False): log.info("######## initial-merge %s ########" % repo.working_tree_dir) _locals, remotes = pyfedpkg._list_branches(repo=repo) aa = [ Branch(repo.git.rev_parse('%s^{tree}' % b), b) for b in remotes ] @@ -171,7 +174,7 @@ def handle_repo(repo): log.info(" %s" % x) n = 0 - f = Filter(repo) + f = Filter(repo, dry_run=dry_run) while n < len(aa): f.eat(aa[n]) n = n + 1 @@ -180,16 +183,16 @@ def handle_repo(repo): log.info("######## /initial-merge %s ########" % repo.working_tree_dir) -def handle_curdir(): +def handle_curdir(dry_run=False): repo = git.Repo() - handle_repo(repo) + handle_repo(repo, dry_run=dry_run) -def handle_path(path=None): +def handle_path(path=None, dry_run=False): if not path: path = os.getcwd() repo = git.Repo(path) - handle_repo(repo) + handle_repo(repo, dry_run=dry_run) class DirListAction(argparse.Action): @@ -211,8 +214,8 @@ def fedpkg_command(args): if is_first: is_first = False else: - print - handle_path(repo_path) + log.info("") + handle_path(repo_path, dry_run=args.dry_run) _module_doc = __doc__ @@ -227,5 +230,8 @@ def add_parser_to(subparsers): nargs='*', default=['.'], action=DirListAction, help = 'Path to a repo to initial-merge') + sp.add_argument('-n', '--dry-run', + default=False, const=True, action='store_const', + help="Whether to run without actually merging") sp.set_defaults(command = fedpkg_command) return sp -- cgit