diff options
author | Guido Günther <agx@sigxcpu.org> | 2015-08-14 11:08:40 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2015-08-14 17:57:17 +0200 |
commit | 035b179b047951f6eb354e748ea0daf7a3221cb9 (patch) | |
tree | aac4cf3b1c2b86c0ec803bb37a58b3ca8fd93a94 | |
parent | d1de3b08d6b1ad785791194c4fa5ab158b6f63f9 (diff) |
import-orig: Add new --merge-mode=replace
This allows one to not merge upstream versions into the debian branch
but rather replace the content of the debian branch and only preserve
the debian/ dirs content.
Closes: #778594
-rw-r--r-- | docs/manpages/gbp-import-orig.sgml | 26 | ||||
-rw-r--r-- | gbp/config.py | 4 | ||||
-rw-r--r-- | gbp/scripts/import_orig.py | 43 |
3 files changed, 68 insertions, 5 deletions
diff --git a/docs/manpages/gbp-import-orig.sgml b/docs/manpages/gbp-import-orig.sgml index 809c46aa..ec10d231 100644 --- a/docs/manpages/gbp-import-orig.sgml +++ b/docs/manpages/gbp-import-orig.sgml @@ -23,6 +23,7 @@ &man.common.options.synopsis; <arg><option>--upstream-version=</option><replaceable>version</replaceable></arg> <arg><option>--[no-]merge</option></arg> + <arg><option>--merge-mode=</option><replaceable>[merge|replace]</replaceable></arg> <arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg> <arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg> <arg><option>--upstream-vcs-tag=</option><replaceable>tag-format</replaceable></arg> @@ -84,6 +85,31 @@ </listitem> </varlistentry> <varlistentry> + <term><option>--merge-mode=</option><replaceable>[merge|replace]</replaceable></term> + <listitem> + <para> + How to fold the newly imported upstream source to the + &debian; packaging branch after import. + </para> + <para> + The default mode + <replaceable>merge</replaceable> does a + &git; <command>merge</command> leaving you on your own in + case of merge conflict resolution. + </para> + <para> + <replaceable>replace</replaceable> mode on the + other hand makes the head of the &debian; packaging branch + identical to the newly imported tree but preserves the + content of the <filename>debian/</filename> directory + while keeping the current head as well as the newly + iportant trees as parents of the generated commit. This is + similar to a <option>theirs</option> merge strategy while + preserving <filename>debian/</filename>. + </para> + </listitem> + </varlistentry> + <varlistentry> <term><option>--upstream-branch</option>=<replaceable>branch_name</replaceable> </term> <listitem> diff --git a/gbp/config.py b/gbp/config.py index 413cb6a8..de8a25ea 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -147,6 +147,7 @@ class GbpOptionParser(OptionParser): 'renumber' : 'False', 'notify' : 'auto', 'merge' : 'True', + 'merge-mode' : 'merge', 'track' : 'True', 'author-is-committer': 'False', 'author-date-is-committer-date': 'False', @@ -266,6 +267,9 @@ class GbpOptionParser(OptionParser): 'merge': ("After the import merge the result to the debian branch, " "default is '%(merge)s'"), + 'merge-mode': + ("Howto merge the new upstream sources onto the debian branch" + "default is '%(merge-mode)s'"), 'track': ("Set up tracking for remote branches, " "default is '%(track)s'"), diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py index d379466a..16573c31 100644 --- a/gbp/scripts/import_orig.py +++ b/gbp/scripts/import_orig.py @@ -174,12 +174,11 @@ def find_source(use_uscan, args): def debian_branch_merge(repo, tag, version, options): - gbp.log.info("Merging to '%s'" % options.debian_branch) - repo.set_branch(options.debian_branch) try: - repo.merge(tag) - except GitRepositoryError: - raise GbpError("Merge failed, please resolve.") + func = globals()["debian_branch_merge_by_%s" % options.merge_mode] + except KeyError: + raise GbpError("%s is not a valid merge mode" % options.merge_mode) + func(repo, tag, version, options) if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): @@ -194,6 +193,39 @@ def debian_branch_merge(repo, tag, version, options): gbpc.Command(format_str(options.postimport, info), extra_env=env, shell=True)() +def debian_branch_merge_by_replace(repo, tag, version, options): + gbp.log.info("Replacing upstream source on '%s'" % options.debian_branch) + + tree = [x for x in repo.list_tree("%s^{tree}" % tag) + if x[-1] != 'debian'] + msg = "Updated version %s from '%s'" % (version, tag) + + # Get the current debian/ tree on the debian branch + try: + deb_sha = [x for x in repo.list_tree("%s^{tree}" % options.debian_branch) + if x[-1] == 'debian' and x[1] == 'tree'][0][2] + tree.append(['040000', 'tree', deb_sha, 'debian']) + msg += "\n\nwith Debian dir %s" % deb_sha + except IndexError: + pass # no debian/ dir is fine + + sha = repo.make_tree(tree) + commit = repo.commit_tree(sha, msg, ["%s^{commit}" % options.debian_branch, + "%s^{commit}" % tag]) + repo.update_ref("refs/heads/%s" % options.debian_branch, commit, + msg="gbp: Updating %s after import of %s" % (options.debian_branch, + tag)) + repo.force_head(commit, hard=True) + + +def debian_branch_merge_by_merge(repo, tag, version, options): + gbp.log.info("Merging to '%s'" % options.debian_branch) + try: + repo.merge(tag) + except GitRepositoryError: + raise GbpError("Merge failed, please resolve.") + repo.set_branch(options.debian_branch) + def set_bare_repo_options(options): """Modify options for import into a bare repository""" @@ -233,6 +265,7 @@ def build_parser(name): branch_group.add_config_file_option(option_name="upstream-vcs-tag", dest="vcs_tag", help="Upstream VCS tag add to the merge commit") branch_group.add_boolean_config_file_option(option_name="merge", dest="merge") + branch_group.add_config_file_option(option_name="merge-mode", dest="merge_mode") tag_group.add_boolean_config_file_option(option_name="sign-tags", dest="sign_tags") |