diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-01-12 15:26:55 +0200 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-05-08 11:39:40 +0300 |
commit | 199feb450bdc3ae0b6a338ca15352b8b166f625d (patch) | |
tree | fff0a2170a3cf4c775066400da05d0d1a4ff263c /gbp/scripts | |
parent | 3897796b9ed3b78f63b0348d8a07d76e85207bfc (diff) | |
download | git-buildpackage-199feb450bdc3ae0b6a338ca15352b8b166f625d.tar.gz git-buildpackage-199feb450bdc3ae0b6a338ca15352b8b166f625d.tar.bz2 git-buildpackage-199feb450bdc3ae0b6a338ca15352b8b166f625d.zip |
gbp-pull: two modes for --force
The 'force' option now has two possible values:
'merge': upstream branch is merged, even if fast-forward is not
possible.
'clean': check out a clean copy from the upstream if fast-forward is not
possible (i.e. no merge). Local changes are lost in this case.
Diffstat (limited to 'gbp/scripts')
-rwxr-xr-x | gbp/scripts/pull.py | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index 260f1074..9a94fdc8 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -35,7 +35,7 @@ def update_branch(branch, repo, options): @return: branch updated or already up to date @rtype: boolean """ - update = False + update = None remote = repo.get_merge_branch(branch) if not remote: @@ -49,30 +49,46 @@ def update_branch(branch, repo, options): return True if can_fast_forward: - update = True + update = 'merge' else: - if options.force: - gbp.log.info("Non-fast forwarding '%s' due to --force" % branch) - update = True + if options.force == 'merge': + gbp.log.info("Non-fast forwarding '%s' due to --force=merge" % branch) + update = 'merge' + elif options.force == 'clean': + gbp.log.info("Checking out clean copy of '%s' due to --force=clean" % branch) + update = 'clean' else: gbp.log.warn("Skipping non-fast forward of '%s' - use --force" % branch) if update: gbp.log.info("Updating '%s'" % branch) if repo.branch == branch: - repo.merge(remote) - elif can_fast_forward: - sha1 = repo.rev_parse(remote) - repo.update_ref("refs/heads/%s" % branch, sha1, - msg="gbp: forward %s to %s" % (branch, remote)) + if update == 'merge': + repo.merge(remote) + elif update == 'clean': + # Have to drop our current branch + tmpbranch = "_gbptmp-"+branch + gbp.log.debug("Checking out '%s' to '%s'" % (remote, tmpbranch)) + repo.create_branch(tmpbranch, remote) + gbp.log.debug("Switching current branch to '%s'" % (tmpbranch)) + repo.set_branch(tmpbranch) + gbp.log.debug("Dropping branch '%s'" % branch) + repo.delete_branch(branch) + gbp.log.info("Renaming branch '%s' to '%s'" % (tmpbranch, branch)) + repo.rename_branch(tmpbranch, branch) else: - # Merge other branch, if it cannot be fast-forwarded - current_branch=repo.branch - repo.set_branch(branch) - repo.merge(remote) - repo.set_branch(current_branch) - - return update + if can_fast_forward or (update == 'clean'): + sha1 = repo.rev_parse(remote) + repo.update_ref("refs/heads/%s" % branch, sha1, + msg="gbp: forward %s to %s" % (branch, remote)) + elif update == 'merge': + # Merge other branch, if it cannot be fast-forwarded + current_branch=repo.branch + repo.set_branch(branch) + repo.merge(remote) + repo.set_branch(current_branch) + + return (update != None) def main(argv): retval = 0 @@ -81,8 +97,8 @@ def main(argv): usage='%prog [options] - safely update a repository from remote') branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options") parser.add_option_group(branch_group) - branch_group.add_option("--force", action="store_true", dest="force", default=False, - help="force a branch update even if can't be fast forwarded") + branch_group.add_option("--force", action="store", dest="force", default=None, + help="force a branch update even if can't be fast forwarded (valid ACTIONs are 'merge', 'clean') ", metavar='ACTION') branch_group.add_option("--redo-pq", action="store_true", dest="redo_pq", default=False, help="redo the patch queue branch after a pull. Warning: this drops the old patch-queue branch") branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") |