Skip to content

Commit 3d79216

Browse files
trastgitster
authored andcommitted
add -p: do not attempt to coalesce mode changes
In 0392513 (add-interactive: refactor mode hunk handling, 2009-04-16), we merged the interaction loops for mode changes and hunk staging. This was fine at the time, because 0beee4c (git-add--interactive: remove hunk coalescing, 2008-07-02) removed hunk coalescing. However, in 7a26e65 (Revert "git-add--interactive: remove hunk coalescing", 2009-05-16), we resurrected it. Since then, the code would attempt in vain to merge mode changes with diff hunks, corrupting both in the process. We add a check to the coalescing loop to ensure it only looks at diff hunks, thus skipping mode changes. Noticed-by: Kirill Smelkov <[email protected]> Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87ca2ea commit 3d79216

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

git-add--interactive.perl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ sub coalesce_overlapping_hunks {
841841
my ($last_o_ctx, $last_was_dirty);
842842

843843
for (grep { $_->{USE} } @in) {
844+
if ($_->{TYPE} ne 'hunk') {
845+
push @out, $_;
846+
next;
847+
}
844848
my $text = $_->{TEXT};
845849
my ($o_ofs) = parse_hunk_header($text->[0]);
846850
if (defined $last_o_ctx &&

t/t3701-add-interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ test_expect_success FILEMODE 'stage mode but not hunk' '
164164
'
165165

166166

167-
test_expect_failure FILEMODE 'stage mode and hunk' '
167+
test_expect_success FILEMODE 'stage mode and hunk' '
168168
git reset --hard &&
169169
echo content >>file &&
170170
chmod +x file &&

0 commit comments

Comments
 (0)