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

[PATCH 2/2] git-gui: fix applying line/ranges when the selection ends at the begin of a line

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
Jan 9, 2012, 13:43 UTC
Message-ID
<37339be035746797fcec7634e3560ffcd5b26cf3.1326116492.git.bert.wesarg@googlemail.com>
In-Reply-To
<cccd6193cf3bfe170e14270204d735a842bb8563.1326116492.git.bert.wesarg@googlemail.com>

Selecting also the trailing newline of a line for staging/unstaging would have resulted in also staging/unstaging of the next line.

Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 lib/diff.tcl |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/lib/diff.tcl b/lib/diff.tcl
index 63f8742..a750ea7 100644
--- a/lib/diff.tcl
+++ b/lib/diff.tcl
@@ -632,7 +632,13 @@ proc apply_range_or_line {x y} {
 	}
 
 	set first_l [$ui_diff index "$first linestart"]
-	set last_l [$ui_diff index "$last lineend"]
+	# don't include the next line if $last points to the start of a line
+	# ie. <lno>.0
+	if {[lindex [split $last .] 1] == 0} {
+		set last_l [$ui_diff index "$last -1 line lineend"]
+	} else {
+		set last_l [$ui_diff index "$last lineend"]
+	}
 
 	if {$current_diff_path eq {} || $current_diff_header eq {}} return
 	if {![lock_index apply_hunk]} return
-- 
1.7.8.1.873.gfea665
Previous: Bert WesargNext: Bert Wesarg
Message 2 of 8 in “git-gui: fix hunk parsing for corner case changes”
  1. 1/1 git-gui: fix hunk parsing for corner case changesBert Wesarg, Jan 9, 2012
  2. 2/2 git-gui: fix applying line/ranges when the selection ends at the begin of a lineBert Wesarg, Jan 9, 2012
  3. 3/3 git-gui: support for reverting hunks and linesBert Wesarg, Jan 9, 2012
  4. Bert WesargJan 14, 2012
  5. Junio C HamanoJan 14, 2012
  6. Bert WesargJan 14, 2012
  7. Bert WesargJan 14, 2012
  8. Bert WesargJan 14, 2012

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.