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> | 2014-11-14 14:22:11 +0200 |
commit | 2d72c556e17230258fb9f8366bf4280436e5f82e (patch) | |
tree | fc3b82264de6d317b45e10bf9fb0fe434c034691 | |
parent | 4b6a2355f0754d0fb87ec3d4718be3c621b16d65 (diff) | |
download | git-buildpackage-2d72c556e17230258fb9f8366bf4280436e5f82e.tar.gz git-buildpackage-2d72c556e17230258fb9f8366bf4280436e5f82e.tar.bz2 git-buildpackage-2d72c556e17230258fb9f8366bf4280436e5f82e.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.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | docs/manpages/gbp-pull.sgml | 13 | ||||
-rwxr-xr-x | gbp/scripts/pull.py | 55 |
2 files changed, 45 insertions, 23 deletions
diff --git a/docs/manpages/gbp-pull.sgml b/docs/manpages/gbp-pull.sgml index de076b7f..5c7f258f 100644 --- a/docs/manpages/gbp-pull.sgml +++ b/docs/manpages/gbp-pull.sgml @@ -22,7 +22,7 @@ &gbp-pull; &man.common.options.synopsis; - <arg><option>--force</option></arg> + <arg><option>--force=</option><replaceable>[merge|clean]</replaceable></arg> <arg><option>--all</option></arg> <arg><option>--redo-pq</option></arg> <arg><option>--[no-]pristine-tar</option></arg> @@ -48,11 +48,14 @@ &man.common.options.description; <varlistentry> - <term><option>--force</option></term> + <term><option>--force=</option><replaceable>[merge|clean]</replaceable></term> <listitem> - <para>force a branch update even if this results in a non fast - forward update. <warning><para>Forcing a branch update - makes you lose your modifications.</para></warning></para> + <para>Force a branch update even if this results in a non fast + forward update. + <emphasis>merge</emphasis> does a git-merge. + <emphasis>clean</emphasis> checks out a clean copy from upstream. + <warning><para>using <emphasis>clean</emphasis> + makes you lose your modifications.</para></warning></para> </listitem> </varlistentry> <varlistentry> diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index a2dafd04..50b04895 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -36,7 +36,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: @@ -50,11 +50,14 @@ 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 or " "update manually" % branch) @@ -62,19 +65,32 @@ def update_branch(branch, repo, options): 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) + 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 + return (update != None) def build_parser(name): @@ -88,8 +104,11 @@ def build_parser(name): branch_group = GbpOptionGroup(parser, "branch options", "branch update and layout options") parser.add_option_group(branch_group) branch_group.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch") - branch_group.add_option("--force", action="store_true", dest="force", default=False, - help="force a branch update even if it can't be fast forwarded") + branch_group.add_option("--force", action="store", dest="force", + default=None, + help="force a branch update even if it can't be fast " + "forwarded (valid ACTIONs are 'merge', 'clean')", + metavar='ACTION') branch_group.add_option("--all", action="store_true", default=False, help="update all remote-tracking branches that " "have identical name in the remote") |