On Sun, 10 Jul 2022 14:34:01 +0200 Gioele Barabucci <gio...@svario.it> wrote:
All that is needed to do two-step merge (first merge the upstream branch, then
apply the debian diff) is to do a merge at the right moment in `import_dsc.py`.

The following quick-and-dirty patch adds such a merge.

[...]

+            tag = os.popen("git tag --list 'upstream/*' --sort=-v:refname | head 
-n1").read().rstrip()
+            os.system(f'git merge {tag} --strategy-option theirs -m "Merge tag 
\'{tag}\'"')
+
              if dsc.diff or dsc.deb_tgz:

The attached new patch, although still "quick and dirty", improves the handing of possible modification+deletion conflicts that may arise while merging the the upstream branch into the Debian branch.

--
Gioele Barabucci
--- /usr/lib/python3/dist-packages/gbp/scripts/import_dsc.py.orig	2023-08-19 13:59:00.391232974 +0200
+++ /usr/lib/python3/dist-packages/gbp/scripts/import_dsc.py	2023-08-19 14:02:05.330777453 +0200
@@ -524,12 +524,20 @@
                 if options.create_missing_branches:
                     repo.create_branch(options.debian_branch, commit)
                 else:
                     raise GbpError("Branch %s does not exist, use --create-missing-branches" %
                                    options.debian_branch)
 
+            tag = os.popen("git tag --list 'upstream/*' --sort=-v:refname | head -n1").read().rstrip()
+            ver = tag.split("/")[1]
+            msg = f"Merge upstream version {ver}"
+            ret = os.system(f'git merge {tag} --strategy-option theirs -m "{msg}"' + " || { git diff --name-only --diff-filter=U | xargs git rm && git commit --no-edit ;}")
+            if ret != 0:
+                gbp.log.err(f"Failed to merge upstream version {ver}")
+                return ret
+
             if dsc.diff or dsc.deb_tgz:
                 apply_debian_patch(repo, sources[0], dsc, commit, options)
             else:
                 gbp.log.warn("Didn't find a diff to apply.")
 
             if imported and options.pristine_tar:

Reply via email to