Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions ProjectDirector.Test/CommitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,43 @@ public void ARenameWhoseSourceLooksLikeARecordIsStillNotListed()
}
}

/// <summary>
/// A rename can also be reported in the worktree column: a file added with intent-to-add that
/// git matches against a deleted tracked file comes out as <c> R</c>. Its source path still
/// follows as a bare entry and must be consumed, or "ab cd.txt" is listed as "cd.txt".
/// </summary>
[TestMethod]
public void AWorktreeRenameReportsOnlyItsDestination()
{
// Arrange
string root = CreateCommittedRepository();

try
{
File.WriteAllText(Path.Join(root, "ab cd.txt"), "moved content\n");
Assert.IsTrue(GitCli.RunIn(root, "add", "--all").Succeeded);
Assert.IsTrue(GitCli.RunIn(root, "commit", "-m", "second").Succeeded);

File.Delete(Path.Join(root, "ab cd.txt"));
File.WriteAllText(Path.Join(root, "new.txt"), "moved content\n");
Assert.IsTrue(GitCli.RunIn(root, "add", "-N", "new.txt").Succeeded, "git add -N failed.");

GitResult status = GitCli.RunIn(root, "status", "--porcelain", "-z");
Assert.StartsWith(" R new.txt\0", status.Output, "git should report the rename in the worktree column.");

// Act
Collection<string> changes = GitCli.ListPendingChanges(root);

// Assert
Assert.HasCount(1, changes);
Assert.AreEqual("new.txt", changes[0]);
}
finally
{
Cleanup(root);
}
}

/// <summary>
/// A path that is not a repository at all reports nothing rather than throwing, so the button
/// degrades to "nothing to commit" instead of taking the application down.
Expand Down
6 changes: 4 additions & 2 deletions ProjectDirector/GitCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,12 @@

changes.Add(entry[3..]);

// A rename or copy is recorded against the index, in the first status character.
if (entry[0] is 'R' or 'C')
// A rename or copy is usually recorded against the index, in the first status character,
// but one detected in the worktree (an intent-to-add file matched against a deleted
// tracked one) is recorded in the second. Either way the source path follows.
if (entry[0] is 'R' or 'C' || entry[1] is 'R' or 'C')
{
++i;

Check warning on line 221 in ProjectDirector/GitCli.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.

Check warning on line 221 in ProjectDirector/GitCli.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.

Check warning on line 221 in ProjectDirector/GitCli.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.

Check warning on line 221 in ProjectDirector/GitCli.cs

View workflow job for this annotation

GitHub Actions / ci / .NET / Analyze & Release

Do not update the stop condition variable 'i' in the body of the for loop.
}
}

Expand Down
Loading