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

[PATCH] git-gui: allow "\ No newline at end of file" for linewise staging

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
May 9, 2013, 16:30 UTC
Message-ID
<20130509163002.GA3630@book-mint>
In-Reply-To
<87vcb6bee5.fsf@fox.patthoyts.tk>

Counting of lines did not skip this line when generating the hunk header.

Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
---
Here is an attempt at fixing the no newline issue. I would appreciate
another pair of eyes though.
 git-gui/lib/diff.tcl | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index ec44055..30d9a79 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -764,8 +764,15 @@ proc apply_range_or_line {x y} {
 				# context line
 				set ln [$ui_diff get $i_l $next_l]
 				set patch "$patch$pre_context$ln"
-				set n [expr $n+1]
-				set m [expr $m+1]
+				# Skip the "\ No newline at end of
+				# file". Depending on the locale setting
+				# we don't know what this line looks
+				# like exactly. The only thing we do
+				# know is that it starts with "\ "
+				if {![string match {\\ *} $ln]} {
+					set n [expr $n+1]
+					set m [expr $m+1]
+				}
 				set pre_context {}
 			} elseif {$c1 eq $to_context} {
 				# turn change line into context line
-- 
1.8.3.rc1.40.gba374ae
Previous: Pat ThoytsNext: Tobias Preuss
Message 4 of 5 in “git-gui / Warning: "No newline at end of file””
  1. Tobias PreussNov 13, 2012
  2. Fwd: git-gui / Warning: "No newline at end of file”Tobias Preuss, Jan 3, 2013
  3. Pat ThoytsJan 9, 2013
  4. git-gui: allow "\ No newline at end of file" for linewise stagingHeiko Voigt, May 9, 2013
  5. Tobias PreussMay 10, 2013

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.