threads / patch / 47574

patch, 4 partsgit gui: fix staging a second line to a 1-line file

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

## tl;dr

8 messages between Jan 9, 2018 and Jan 10, 2018. Diffs are folded; open one to read it.

replies: 7people: 2as markdown or json

Johannes Schindelin· Jan 9, 2018, 14:32 UTC · lore

[PATCH 0/4] "Fast-"track Git GUI changes

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
Johannes Schindelin· Jan 9, 2018, 14:32 UTC · re: Johannes Schindelin · lore

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(+)
Show changes to git-gui/lib/diff.tcl +1 −0
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· Jan 9, 2018, 14:32 UTC · re: Johannes Schindelin · lore

[PATCH 2/4] git-gui: avoid exception upon Ctrl+T in an empty list

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(+)
Show changes to git-gui/git-gui.sh +4 −0
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· Jan 9, 2018, 14:33 UTC · re: Johannes Schindelin · lore

[PATCH 3/4] git-gui: fix exception when trying to stage with empty file list

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(-)
Show changes to git-gui/git-gui.sh +10 −2
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· Jan 9, 2018, 14:33 UTC · re: Johannes Schindelin · lore

[PATCH 4/4] git-gui: allow Ctrl+T to toggle multiple paths

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(+)
Show changes to git-gui/git-gui.sh +13 −0
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
Junio C Hamano· Jan 9, 2018, 19:01 UTC · re: Johannes Schindelin · lore

Re: [PATCH 0/4] "Fast-"track Git GUI changes

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.

Show 5 quoted lines
> 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· Jan 9, 2018, 19:09 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/4] "Fast-"track Git GUI changes

Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> 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· Jan 10, 2018, 14:30 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/4] "Fast-"track Git GUI changes

Hi,
On Tue, 9 Jan 2018, Junio C Hamano wrote:
Show 29 quoted lines
> 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

← back to recent threads