diff mbox series

b4 can't diff a series with a file renamed, then modified

Message ID e759026c-4f49-cc2a-7885-10b88212d20e@gmail.com (mailing list archive)
State Superseded
Headers show
Series b4 can't diff a series with a file renamed, then modified | expand

Commit Message

Philippe Blain Oct. 26, 2022, 1:01 p.m. UTC
Hi Konstantin,

I'm hitting a bug when running 'b4 diff' on https://lore.kernel.org/git/pull.1321.v2.git.git.1666297238.gitgitgadget@gmail.com/.

Here is a reproducer in a clone of git.git:

git checkout 9bf691b78c # the base commit of v1
b4 am -v 1 -o- https://lore.kernel.org/git/pull.1321.v2.git.git.1666297238.gitgitgadget@gmail.com  | git am # apply v1 to get the necessary blobs
b4 -d diff -C -n https://lore.kernel.org/git/pull.1321.v2.git.git.1666297238.gitgitgadget@gmail.com/

This is on b4's 2a16f70 (am: ignore base-commit info if commit not present, 2022-10-19).

The 'b4 diff' command errors like so:

    Looking at [PATCH 3/6] t5617: drop references to remote-tracking branches
    ERROR: some patches do not have indexes
           unable to create a fake-am range
    Running git --no-pager worktree remove --force /var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/tmp7hpz_ac1
    ---
    Could not create fake-am range for lower series v1

I looked through the code and found that LoreMessage::get_indexes
is not ready for rename patches, since the "rename" lines in the 'git diff' output
is placed between the 'diff --git' line and the 'index' line, which the code does 
not account for. This seems to help:


With this change, the 'b4 diff' command goes a little further, but still fails:

    Running git --no-pager write-tree
    Running git --no-pager commit-tree 565d875b4fdf449501853a9bcbe608e4374d9eed^{tree} -F -
    Running git --no-pager reset --hard 1149ea03d905ba0a51d1c80e6352361cf34feee1
    Running git --no-pager am .__git-am__
    ERROR: Could not fake-am version 1
    Running git --no-pager worktree remove --force /var/folders/lr/r6n2057j0dzd4gdb614fp0740000gp/T/tmp1h_x78kk
    ---
    Could not create fake-am range for lower series v1

I ran the 'git am' command manually in the temporary worktree, and this is what it outputs:

    $ git am .__git-am__
    Applying: clone: teach --detach option
    warning: t/t5601-clone.sh has type 100644, expected 100755
    Applying: repo-settings: add submodule_propagate_branches
    Applying: t5617: drop references to remote-tracking branches
    warning: t/t5617-clone-submodules-remote.sh has type 100644, expected 100755
    error: t/t5617-clone-submodules.sh: already exists in index
    Patch failed at 0003 t5617: drop references to remote-tracking branches
    hint: Use 'git am --show-current-patch=diff' to see the failed patch
    When you have resolved this problem, run "git am --continue".
    If you prefer to skip this patch, run "git am --skip" instead.
    To restore the original branch and stop patching, run "git am --abort".

It aborts at 3/6 because t/t5617-clone-submodules.sh (the new name of the renamed file)
already exists in the index. From what I understand of LoreSeries::make_fake_am_range, this
is because it gets added to the index when preparing the initial fake commit because
6/6 modifies it.

Thanks,
Philippe.
diff mbox series

Patch

diff --git a/b4/__init__.py b/b4/__init__.py
index 4456414..fb618c7 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -1517,7 +1517,7 @@  class LoreMessage:
             if line.find('diff ') != 0 and line.find('index ') != 0:
                 continue
             matches = re.search(r'^diff\s+--git\s+\w/(.*)\s+\w/(.*)$', line)
-            if matches and matches.groups()[0] == matches.groups()[1]:
+            if matches:
                 curfile = matches.groups()[0]
                 continue
             matches = re.search(r'^index\s+([\da-f]+)\.\.[\da-f]+.*$', line)