threads / discuss / 32104

git-gui / Warning: "No newline at end of file”

Subject: git-gui / Warning: "No newline at end of file”

## tl;dr

5 messages between Nov 13, 2012 and May 10, 2013.

replies: 4people: 3as markdown or json

Tobias Preuss· Nov 13, 2012, 20:26 UTC · lore

Hello. I noticed a problem when working with git-gui which might be a bug. The issue only affects you when you are visually trying to stage changes line by line. Here are the steps to reproduce the problem:

1. Initialize a new repository.
2. Create a file with three lines of content each with the word
"Hello". Do not put a new line at the end of the file.
3. Add and commit the file.
4. Edit the same file putting words inbetween the three lines.
5. Open git-gui and try to stage the changes line by line.

The editor will append the warning "No newline at end of file” to the end of the diff. When you are trying to stage a line an error occurs. The problem is also illustrated in a question on Stackoverflow [1].

Please let me know if you need more information or if I should send this problem to some other mailing list. Thank you, Tobias

____________ [1] http://stackoverflow.com/questions/13223868/how-to-stage-line-by-line-in-git-gui-although-no-newline-at-end-of-file-warnin

Tobias Preuss· Jan 3, 2013, 12:26 UTC · re: Tobias Preuss · lore

Fwd: git-gui / Warning: "No newline at end of file”

Hello. I never got a response. Did my email pass the distribution list? Best, Tobias

---------- Forwarded message ----------
From: Tobias Preuss <tobias.preuss@googlemail.com>
Date: Tue, Nov 13, 2012 at 9:26 PM
Subject: git-gui / Warning: "No newline at end of file”
To: git <git@vger.kernel.org>

Hello. I noticed a problem when working with git-gui which might be a bug. The issue only affects you when you are visually trying to stage changes line by line. Here are the steps to reproduce the problem:

1. Initialize a new repository.
2. Create a file with three lines of content each with the word
"Hello". Do not put a new line at the end of the file.
3. Add and commit the file.
4. Edit the same file putting words inbetween the three lines.
5. Open git-gui and try to stage the changes line by line.

The editor will append the warning "No newline at end of file” to the end of the diff. When you are trying to stage a line an error occurs. The problem is also illustrated in a question on Stackoverflow [1].

Please let me know if you need more information or if I should send this problem to some other mailing list. Thank you, Tobias

____________ [1] http://stackoverflow.com/questions/13223868/how-to-stage-line-by-line-in-git-gui-although-no-newline-at-end-of-file-warnin

Pat Thoyts· Jan 9, 2013, 14:49 UTC · lore

Re: Fwd: git-gui / Warning: "No newline at end of file”

Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
>Tobias Preuss <tobias.preuss@googlemail.com> writes:
>
>> Hello. I never got a response. Did my email pass the distribution
>> list? Best, Tobias
>
>Pat?
>

I did have a brief look at this but I don't have a solution at the moment. The "\ No newline at end of file" is emitted by git at we don't appear to handle it well in the lib/diff.tcl apply_range_or_line function.

Show 30 quoted lines
>> ---------- Forwarded message ----------
>> From: Tobias Preuss <tobias.preuss@googlemail.com>
>> Date: Tue, Nov 13, 2012 at 9:26 PM
>> Subject: git-gui / Warning: "No newline at end of file”
>> To: git <git@vger.kernel.org>
>>
>>
>> Hello.
>> I noticed a problem when working with git-gui which might be a bug.
>> The issue only affects you when you are visually trying to stage
>> changes line by line. Here are the steps to reproduce the problem:
>>
>> 1. Initialize a new repository.
>> 2. Create a file with three lines of content each with the word
>> "Hello". Do not put a new line at the end of the file.
>> 3. Add and commit the file.
>> 4. Edit the same file putting words inbetween the three lines.
>> 5. Open git-gui and try to stage the changes line by line.
>>
>> The editor will append the warning "No newline at end of file” to the
>> end of the diff. When you are trying to stage a line an error occurs.
>> The problem is also illustrated in a question on Stackoverflow [1].
>>
>> Please let me know if you need more information or if I should send
>> this problem to some other mailing list.
>> Thank you, Tobias
>>
>> ____________
>> [1] http://stackoverflow.com/questions/13223868/how-to-stage-line-by-line-in-git-gui-although-no-newline-at-end-of-file-warnin
>
-- 
Pat Thoyts                            http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD
Heiko Voigt· May 9, 2013, 16:30 UTC · re: Pat Thoyts · lore

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

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
Tobias Preuss· May 10, 2013, 19:09 UTC · re: Heiko Voigt · lore

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

I tested the patch as I am the same person that bothered about the
behavior a while ago. Please merge.
- Sorry for sending an HTML formatted mail before.
On Thu, May 9, 2013 at 6:30 PM, Heiko Voigt <hvoigt@hvoigt.net> wrote:
Show 36 quoted lines
> 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
>

← back to recent threads