git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] add -p: do not attempt to coalesce mode changes

From
Thomas Rast <trast@student.ethz.ch>
Date
Aug 15, 2009, 13:56 UTC
Message-ID
<770693df8f416615f57423141fb59f3d6eccc915.1250344341.git.trast@student.ethz.ch>
In-Reply-To
<1250339209-27962-1-git-send-email-kirr@mns.spb.ru>

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 <kirr@mns.spb.ru>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 git-add--interactive.perl  |    4 ++++
 t/t3701-add-interactive.sh |    2 +-
 2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index df9f231..06f7060 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -841,6 +841,10 @@
 	my ($last_o_ctx, $last_was_dirty);
 
 	for (grep { $_->{USE} } @in) {
+		if ($_->{TYPE} ne 'hunk') {
+			push @out, $_;
+			next;
+		}
 		my $text = $_->{TEXT};
 		my ($o_ofs) = parse_hunk_header($text->[0]);
 		if (defined $last_o_ctx &&
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index d5e9351..62fd65e 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -164,7 +164,7 @@ test_expect_success FILEMODE 'stage mode but not hunk' '
 '
 
 
-test_expect_failure FILEMODE 'stage mode and hunk' '
+test_expect_success FILEMODE 'stage mode and hunk' '
 	git reset --hard &&
 	echo content >>file &&
 	chmod +x file &&
-- 
1.6.4.288.gc754a.dirty
Previous: Kirill SmelkovNext: Jeff King
Message 2 of 6 in “git add -p: demonstrate failure when staging both mode and hunk”
  1. git add -p: demonstrate failure when staging both mode and hunkKirill Smelkov, Aug 15, 2009
  2. add -p: do not attempt to coalesce mode changesThomas Rast, Aug 15, 2009
  3. Jeff KingAug 15, 2009
  4. Thomas RastAug 15, 2009
  5. Junio C HamanoAug 15, 2009
  6. Kirill SmelkovAug 18, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.