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

[PATCH (GIT-GUI) 7/8] git-gui: Make F5 reselect a diff, if an untracked file is selected.

From
Alexander Gavrilov <angavrilov@gmail.com>
Date
Aug 30, 2008, 21:04 UTC
Message-ID
<200808310104.11048.angavrilov@gmail.com>
In-Reply-To
<200808310102.56795.angavrilov@gmail.com>

If an untracked file is selected, F5 and other manual rescan synonyms would try to select a tracked file instead. Also, clicking on an icon in the unstaged changes list skips over untracked files, unless the file clicked is untracked itself.

The objective is to make it easier to ignore untracked files showing up in the Unstaged Changes list, and ensure that no modifications to tracked objects are left unstaged.

Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com>
---
 git-gui.sh |   44 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 35 insertions(+), 9 deletions(-)
diff --git a/git-gui.sh b/git-gui.sh
index f84f436..fde44a6 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1817,6 +1817,10 @@ proc do_rescan {} {
 	rescan ui_ready
 }
 
+proc ui_do_rescan {} {
+	rescan {force_first_diff; ui_ready}
+}
+
 proc do_commit {} {
 	commit_tree
 }
@@ -1917,6 +1921,18 @@ proc select_first_diff {} {
 	}
 }
 
+proc force_first_diff {} {
+	global current_diff_path
+
+	if {[info exists file_states($current_diff_path)]} {
+		set state [lindex $file_states($current_diff_path) 0]
+
+		if {[string index $state 1] ne {O}} return
+	}
+
+	select_first_diff
+}
+
 proc toggle_or_diff {w x y} {
 	global file_states file_lists current_diff_path ui_index ui_workdir
 	global last_clicked selected_paths
@@ -1938,13 +1954,23 @@ proc toggle_or_diff {w x y} {
 	# Do not stage files with conflicts
 	if {[info exists file_states($path)]} {
 		set state [lindex $file_states($path) 0]
-		if {[string first {U} $state] >= 0} {
-			set col 1
-		}
+	} else {
+		set state {__}
+	}
+
+	if {[string first {U} $state] >= 0} {
+		set col 1
 	}
 
+	# Restage the file, or simply show the diff
 	if {$col == 0 && $y > 1} {
-		set after [next_diff_after_action $w $path $lno]
+		if {[string index $state 1] eq {O}} {
+			set mmask {}
+		} else {
+			set mmask {[^O]}
+		}
+
+		set after [next_diff_after_action $w $path $lno $mmask]
 
 		if {$w eq $ui_index} {
 			update_indexinfo \
@@ -2208,7 +2234,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
 	.mbar.commit add separator
 
 	.mbar.commit add command -label [mc Rescan] \
-		-command do_rescan \
+		-command ui_do_rescan \
 		-accelerator F5
 	lappend disable_on_lock \
 		[list .mbar.commit entryconf [.mbar.commit index last] -state]
@@ -2564,7 +2590,7 @@ pack .vpane.lower.commarea.buttons.l -side top -fill x
 pack .vpane.lower.commarea.buttons -side left -fill y
 
 button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
-	-command do_rescan
+	-command ui_do_rescan
 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
 lappend disable_on_lock \
 	{.vpane.lower.commarea.buttons.rescan conf -state}
@@ -2985,9 +3011,9 @@ if {[is_enabled transport]} {
 	bind . <$M1B-Key-P> do_push_anywhere
 }
 
-bind .   <Key-F5>     do_rescan
-bind .   <$M1B-Key-r> do_rescan
-bind .   <$M1B-Key-R> do_rescan
+bind .   <Key-F5>     ui_do_rescan
+bind .   <$M1B-Key-r> ui_do_rescan
+bind .   <$M1B-Key-R> ui_do_rescan
 bind .   <$M1B-Key-s> do_signoff
 bind .   <$M1B-Key-S> do_signoff
 bind .   <$M1B-Key-t> do_add_selection
-- 
1.6.0.20.g6148bc
Previous: Alexander GavrilovNext: Alexander Gavrilov
Message 8 of 21 in “Add mergetool functionality to git-gui.”
  1. 0/8 Add mergetool functionality to git-gui.Alexander Gavrilov, Aug 30, 2008
  2. 1/8 git-gui: Don't allow staging files with conflicts.Alexander Gavrilov, Aug 30, 2008
  3. 2/8 git-gui: Support resolving conflicts via the diff context menu.Alexander Gavrilov, Aug 30, 2008
  4. 3/8 git-gui: Support calling merge tools.Alexander Gavrilov, Aug 30, 2008
  5. 4/8 git-gui: Support more merge tools.Alexander Gavrilov, Aug 30, 2008
  6. 5/8 git-gui: Support conflict states _U & UT.Alexander Gavrilov, Aug 30, 2008
  7. 6/8 git-gui: Reimplement and enhance auto-selection of diffs.Alexander Gavrilov, Aug 30, 2008
  8. 7/8 git-gui: Make F5 reselect a diff, if an untracked file is selected.Alexander Gavrilov, Aug 30, 2008
  9. 8/8 git-gui: Show special diffs for complex conflict cases.Alexander Gavrilov, Aug 30, 2008
  10. Johannes SixtSep 8, 2008
  11. Alexander GavrilovSep 8, 2008
  12. 0/2 git-gui: issues with merge tool seriesJohannes Sixt, Sep 17, 2008
  13. 1/2 Revert "git-gui: Don't allow staging files with conflicts."Johannes Sixt, Sep 17, 2008
  14. 2/2 git-gui: Do not automatically stage file after merge tool finishesJohannes Sixt, Sep 17, 2008
  15. Alexander GavrilovSep 17, 2008
  16. Shawn O. PearceSep 24, 2008
  17. 2/2 git-gui: Do not automatically stage file after merge tool finishesJohannes Sixt, Sep 24, 2008
  18. Alexander GavrilovSep 17, 2008
  19. Johannes SixtSep 17, 2008
  20. Alexander GavrilovSep 17, 2008
  21. Shawn O. PearceSep 24, 2008

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.