Show renames when diffing a directory that a file was moved into or out of

Git limits its tree diff by the pathspec before it looks for renames, so
a directory only ever gets one end of a rename whose other end is outside
it. Nothing is left to pair up, and the file turns into an addition or a
deletion that the commit doesn't contain.

Pass the other end along with the directory. This is bounded by the
number of renames that cross the directory's boundary, so it costs
nothing at all for the vast majority of commits.
This commit is contained in:
Stefan Haller
2026-08-17 09:32:30 +02:00
parent 40cb4bb24d
commit bee03d3b98
6 changed files with 128 additions and 57 deletions
@@ -61,7 +61,6 @@ var DirectoryDiffWithRenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{
SelectedLine(Equals(" ▼ dir"))
t.Views().Main().
/* EXPECTED:
ContainsLines(
Equals("diff --git a/file1 b/dir/file1"),
Equals("similarity index 100%"),
@@ -76,27 +75,6 @@ var DirectoryDiffWithRenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{
Equals("rename from dir/nested/file3"),
Equals("rename to file3"),
)
ACTUAL: */
ContainsLines(
Equals("diff --git a/dir/file1 b/dir/file1"),
Equals("new file mode 100644"),
Contains("index"),
Equals("--- /dev/null"),
Equals("+++ b/dir/file1"),
Equals("@@ -0,0 +1 @@"),
Equals("+file1 content"),
Equals("diff --git a/dir/file2 b/dir/file2-renamed"),
Equals("similarity index 100%"),
Equals("rename from dir/file2"),
Equals("rename to dir/file2-renamed"),
Equals("diff --git a/dir/nested/file3 b/dir/nested/file3"),
Equals("deleted file mode 100644"),
Contains("index"),
Equals("--- a/dir/nested/file3"),
Equals("+++ /dev/null"),
Equals("@@ -1 +0,0 @@"),
Equals("-file3 content"),
)
t.Views().CommitFiles().
SelectNextItem().
@@ -52,7 +52,6 @@ var DirectoryDiffWithRenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{
SelectedLine(Equals(" ▼ dir"))
t.Views().Main().
/* EXPECTED:
ContainsLines(
Equals("diff --git a/file1 b/dir/file1"),
Equals("similarity index 100%"),
@@ -67,27 +66,6 @@ var DirectoryDiffWithRenamedFiles = NewIntegrationTest(NewIntegrationTestArgs{
Equals("rename from dir/nested/file3"),
Equals("rename to file3"),
)
ACTUAL: */
ContainsLines(
Equals("diff --git a/dir/file1 b/dir/file1"),
Equals("new file mode 100644"),
Contains("index"),
Equals("--- /dev/null"),
Equals("+++ b/dir/file1"),
Equals("@@ -0,0 +1 @@"),
Equals("+file1 content"),
Equals("diff --git a/dir/file2 b/dir/file2-renamed"),
Equals("similarity index 100%"),
Equals("rename from dir/file2"),
Equals("rename to dir/file2-renamed"),
Equals("diff --git a/dir/nested/file3 b/dir/nested/file3"),
Equals("deleted file mode 100644"),
Contains("index"),
Equals("--- a/dir/nested/file3"),
Equals("+++ /dev/null"),
Equals("@@ -1 +0,0 @@"),
Equals("-file3 content"),
)
// The same applies when a filter reduces the directory to a single file
t.Views().Files().