# [PATCH 1/4] git gui: fix staging a second line to a 1-line file

8 messages from 2018-01-09 to 2018-01-10. Participants: Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/47574

## Johannes Schindelin, 2018-01-09 14:32

Subject: [PATCH 1/4] git gui: fix staging a second line to a 1-line file
Message-ID: <35fabf987c49f3d2adfbbd5b18edcebe3cf06542.1515508360.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/35fabf987c49f3d2adfbbd5b18edcebe3cf06542.1515508360.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1515508360.git.johannes.schindelin@gmx.de>

```
When a 1-line file is augmented by a second line, and the user tries to
stage that single line via the "Stage Line" context menu item, we do not
want to see "apply: corrupt patch at line 5".

The reason for this error was that the hunk header looks like this:

	@@ -1 +1,2 @@

but the existing code expects the original range always to contain a
comma. This problem is easily fixed by cutting the string "1 +1,2"
(that Git GUI formerly mistook for the starting line) at the space.

This fixes https://github.com/git-for-windows/git/issues/515

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-gui/lib/diff.tcl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl
index 4cae10a4c7f..68c4a6c7366 100644
--- a/git-gui/lib/diff.tcl
+++ b/git-gui/lib/diff.tcl
@@ -698,6 +698,7 @@ proc apply_range_or_line {x y} {
 		set hh [$ui_diff get $i_l "$i_l + 1 lines"]
 		set hh [lindex [split $hh ,] 0]
 		set hln [lindex [split $hh -] 1]
+		set hln [lindex [split $hln " "] 0]
 
 		# There is a special situation to take care of. Consider this
 		# hunk:
-- 
2.15.1.windows.2.395.g5bb0817ee52



```

## Johannes Schindelin, 2018-01-09 14:32

Subject: [PATCH 2/4] git-gui: avoid exception upon Ctrl+T in an empty list
Message-ID: <7cd5ed902e3d8102903d494ba3450b1d745928a9.1515508360.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/7cd5ed902e3d8102903d494ba3450b1d745928a9.1515508360.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1515508360.git.johannes.schindelin@gmx.de>

```
Previously unstaged files can be staged by clicking on them and then
pressing Ctrl+T. Conveniently, the next unstaged file is selected
automatically so that the unstaged files can be staged by repeatedly
pressing Ctrl+T.

When a user hits Ctrl+T one time too many, though, Git GUI used to throw
this exception:

	expected number but got ""
	expected number but got ""
	    while executing
	"expr {int([lindex [$w tag ranges in_diff] 0])}"
	    (procedure "toggle_or_diff" line 13)
	    invoked from within
	"toggle_or_diff toggle .vpane.files.workdir.list "
	    (command bound to event)

Let's just avoid that by skipping the operation when there are no more
files to stage.

This fixes https://github.com/git-for-windows/git/issues/1060

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-gui/git-gui.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index ed24aa9d2f1..3c085cddc61 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -2504,6 +2504,10 @@ proc toggle_or_diff {mode w args} {
 		if {$last_clicked ne {}} {
 			set lno [lindex $last_clicked 1]
 		} else {
+			if {[llength $file_lists($w)] == 0} {
+				set last_clicked {}
+				return
+			}
 			set lno [expr {int([lindex [$w tag ranges in_diff] 0])}]
 		}
 		if {$mode eq "toggle"} {
-- 
2.15.1.windows.2.395.g5bb0817ee52



```

## Johannes Schindelin, 2018-01-09 14:33

Subject: [PATCH 3/4] git-gui: fix exception when trying to stage with empty file list
Message-ID: <c227a5f8354c736abca92e9b040f7e6f569af119.1515508360.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/c227a5f8354c736abca92e9b040f7e6f569af119.1515508360.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1515508360.git.johannes.schindelin@gmx.de>

```
If there is nothing to stage, there is nothing to stage. Let's not try
to, even if the file list contains nothing at all.

This fixes https://github.com/git-for-windows/git/issues/1075

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-gui/git-gui.sh | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 3c085cddc61..ca2cdebdc4f 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -2504,7 +2504,9 @@ proc toggle_or_diff {mode w args} {
 		if {$last_clicked ne {}} {
 			set lno [lindex $last_clicked 1]
 		} else {
-			if {[llength $file_lists($w)] == 0} {
+			if {![info exists file_lists]
+				|| ![info exists file_lists($w)]
+				|| [llength $file_lists($w)] == 0} {
 				set last_clicked {}
 				return
 			}
@@ -2518,7 +2520,13 @@ proc toggle_or_diff {mode w args} {
 		}
 	}
 
-	set path [lindex $file_lists($w) [expr {$lno - 1}]]
+	if {![info exists file_lists]
+		|| ![info exists file_lists($w)]
+		|| [llength $file_lists($w)] < $lno - 1} {
+		set path {}
+	} else {
+		set path [lindex $file_lists($w) [expr {$lno - 1}]]
+	}
 	if {$path eq {}} {
 		set last_clicked {}
 		return
-- 
2.15.1.windows.2.395.g5bb0817ee52



```

## Johannes Schindelin, 2018-01-09 14:33

Subject: [PATCH 4/4] git-gui: allow Ctrl+T to toggle multiple paths
Message-ID: <3f01f30f6fce762e127c45c361b009e7b6de33b4.1515508360.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/3f01f30f6fce762e127c45c361b009e7b6de33b4.1515508360.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1515508360.git.johannes.schindelin@gmx.de>

```
It is possible to select multiple files in the "Unstaged Changes" and
the "Staged Changes" lists. But when hitting Ctrl+T, surprisingly only
one entry is handled, not all selected ones.

Let's just use the same code path as for the "Stage To Commit" and the
"Unstage From Commit" menu items.

This fixes https://github.com/git-for-windows/git/issues/1012

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 git-gui/git-gui.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index ca2cdebdc4f..91c00e64893 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -2501,6 +2501,19 @@ proc toggle_or_diff {mode w args} {
 		set pos [split [$w index @$x,$y] .]
 		foreach {lno col} $pos break
 	} else {
+		if {$mode eq "toggle"} {
+			if {$w eq $ui_workdir} {
+				do_add_selection
+				set last_clicked {}
+				return
+			}
+			if {$w eq $ui_index} {
+				do_unstage_selection
+				set last_clicked {}
+				return
+			}
+		}
+
 		if {$last_clicked ne {}} {
 			set lno [lindex $last_clicked 1]
 		} else {
-- 
2.15.1.windows.2.395.g5bb0817ee52

```

## Johannes Schindelin, 2018-01-09 14:32

Subject: [PATCH 0/4] "Fast-"track Git GUI changes
Message-ID: <cover.1515508360.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/cover.1515508360.git.johannes.schindelin%40gmx.de

```
As it seems to be impossible to get the attention of the Git GUI
maintainer these "days" (I have opened Pull Requests on October 16th
2016 that have not even been looked at), let's just side-step that
contribution path which seems to be dormant.

These fixes have been in Git for Windows for various amounts of time.

Note: there are more Git GUI changes in Git for Windows, I only
accumulated the ones I deem wort considering for inclusion into v2.16.0,
still.


Johannes Schindelin (4):
  git gui: fix staging a second line to a 1-line file
  git-gui: avoid exception upon Ctrl+T in an empty list
  git-gui: fix exception when trying to stage with empty file list
  git-gui: allow Ctrl+T to toggle multiple paths

 git-gui/git-gui.sh   | 27 ++++++++++++++++++++++++++-
 git-gui/lib/diff.tcl |  1 +
 2 files changed, 27 insertions(+), 1 deletion(-)


base-commit: 36438dc19dd2a305dddebd44bf7a65f1a220075b
Published-As: https://github.com/dscho/git/releases/tag/misc-git-gui-stuff-v1
Fetch-It-Via: git fetch https://github.com/dscho/git misc-git-gui-stuff-v1
-- 
2.15.1.windows.2.395.g5bb0817ee52


```

## Junio C Hamano, 2018-01-09 19:01

Subject: Re: [PATCH 0/4] "Fast-"track Git GUI changes
Message-ID: <xmqqinca6em2.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqinca6em2.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <cover.1515508360.git.johannes.schindelin@gmx.de>

```
Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> As it seems to be impossible to get the attention of the Git GUI
> maintainer these "days" (I have opened Pull Requests on October 16th
> 2016 that have not even been looked at), let's just side-step that
> contribution path which seems to be dormant.

Good to see that finally somebody else steps up after I did the same
for a few times recently.

> These fixes have been in Git for Windows for various amounts of time.
>
> Note: there are more Git GUI changes in Git for Windows, I only
> accumulated the ones I deem wort considering for inclusion into v2.16.0,
> still.

Thanks.  I am not sure if it is too late for 2.16, as these are not
fixes for regression during this cycle, though.


```

## Junio C Hamano, 2018-01-09 19:09

Subject: Re: [PATCH 0/4] "Fast-"track Git GUI changes
Message-ID: <xmqqbmi26e84.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqbmi26e84.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <xmqqinca6em2.fsf@gitster.mtv.corp.google.com>

```
Junio C Hamano <gitster@pobox.com> writes:

> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
>
>> As it seems to be impossible to get the attention of the Git GUI
>> maintainer these "days" (I have opened Pull Requests on October 16th
>> 2016 that have not even been looked at), let's just side-step that
>> contribution path which seems to be dormant.
>
> Good to see that finally somebody else steps up after I did the same
> for a few times recently.
>
>> These fixes have been in Git for Windows for various amounts of time.
>>
>> Note: there are more Git GUI changes in Git for Windows, I only
>> accumulated the ones I deem wort considering for inclusion into v2.16.0,
>> still.
>
> Thanks.  I am not sure if it is too late for 2.16, as these are not
> fixes for regression during this cycle, though.

Heh, I changed my mind.  

Just like I pretended to be interim maintainer of Git-GUI for the
past two times, you are doing the same this time and I even agreed
that it was a good thing that you volunteered to pretend as one.

So let's follow through the pretence to its conclusion and merge
these directly to 'master'.

Thanks.

```

## Johannes Schindelin, 2018-01-10 14:30

Subject: Re: [PATCH 0/4] "Fast-"track Git GUI changes
Message-ID: <nycvar.QRO.7.76.6.1801101530010.37@ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz>
URL: https://gitlist.dev/e/nycvar.QRO.7.76.6.1801101530010.37%40ZVAVAG-6OXH6DA.rhebcr.pbec.zvpebfbsg.pbz
In-Reply-To: <xmqqbmi26e84.fsf@gitster.mtv.corp.google.com>

```
Hi,

On Tue, 9 Jan 2018, Junio C Hamano wrote:

> Junio C Hamano <gitster@pobox.com> writes:
> 
> > Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> >
> >> As it seems to be impossible to get the attention of the Git GUI
> >> maintainer these "days" (I have opened Pull Requests on October 16th
> >> 2016 that have not even been looked at), let's just side-step that
> >> contribution path which seems to be dormant.
> >
> > Good to see that finally somebody else steps up after I did the same
> > for a few times recently.
> >
> >> These fixes have been in Git for Windows for various amounts of time.
> >>
> >> Note: there are more Git GUI changes in Git for Windows, I only
> >> accumulated the ones I deem wort considering for inclusion into v2.16.0,
> >> still.
> >
> > Thanks.  I am not sure if it is too late for 2.16, as these are not
> > fixes for regression during this cycle, though.
> 
> Heh, I changed my mind.  
> 
> Just like I pretended to be interim maintainer of Git-GUI for the
> past two times, you are doing the same this time and I even agreed
> that it was a good thing that you volunteered to pretend as one.
> 
> So let's follow through the pretence to its conclusion and merge
> these directly to 'master'.

Thank you, fellow pretender.

Ciao,
Dscho

```
