@matheusbsbs / matheus-bagliano / commits / 8056cc4f29
Fork 0

git-gui: Make F5 reselect a diff, if an untracked file is selected.

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> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Alexander Gavrilov committed Aug 31, 2008 at 01:04 UTC 8056cc4f293b5e2bf0520f085e25b127c2ef3bbf
1 file changed +35 -9
git-gui.sh
+35 -9
@@ -1817,6 +1817,10 @@ proc do_rescan {} {
1817 rescan ui_ready
1818 }
1819
1820 +proc ui_do_rescan {} {
1821 + rescan {force_first_diff; ui_ready}
1822 +}
1823 +
1824 proc do_commit {} {
1825 commit_tree
1826 }
@@ -1917,6 +1921,18 @@ proc select_first_diff {} {
1921 }
1922 }
1923
1924 +proc force_first_diff {} {
1925 + global current_diff_path
1926 +
1927 + if {[info exists file_states($current_diff_path)]} {
1928 + set state [lindex $file_states($current_diff_path) 0]
1929 +
1930 + if {[string index $state 1] ne {O}} return
1931 + }
1932 +
1933 + select_first_diff
1934 +}
1935 +
1936 proc toggle_or_diff {w x y} {
1937 global file_states file_lists current_diff_path ui_index ui_workdir
1938 global last_clicked selected_paths
@@ -1938,13 +1954,23 @@ proc toggle_or_diff {w x y} {
1954 # Do not stage files with conflicts
1955 if {[info exists file_states($path)]} {
1956 set state [lindex $file_states($path) 0]
1941 - if {[string first {U} $state] >= 0} {
1942 - set col 1
1943 - }
1957 + } else {
1958 + set state {__}
1959 + }
1960 +
1961 + if {[string first {U} $state] >= 0} {
1962 + set col 1
1963 }
1964
1965 + # Restage the file, or simply show the diff
1966 if {$col == 0 && $y > 1} {
1947 - set after [next_diff_after_action $w $path $lno]
1967 + if {[string index $state 1] eq {O}} {
1968 + set mmask {}
1969 + } else {
1970 + set mmask {[^O]}
1971 + }
1972 +
1973 + set after [next_diff_after_action $w $path $lno $mmask]
1974
1975 if {$w eq $ui_index} {
1976 update_indexinfo \
@@ -2208,7 +2234,7 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {
2234 .mbar.commit add separator
2235
2236 .mbar.commit add command -label [mc Rescan] \
2211 - -command do_rescan \
2237 + -command ui_do_rescan \
2238 -accelerator F5
2239 lappend disable_on_lock \
2240 [list .mbar.commit entryconf [.mbar.commit index last] -state]
@@ -2564,7 +2590,7 @@ pack .vpane.lower.commarea.buttons.l -side top -fill x
2590 pack .vpane.lower.commarea.buttons -side left -fill y
2591
2592 button .vpane.lower.commarea.buttons.rescan -text [mc Rescan] \
2567 - -command do_rescan
2593 + -command ui_do_rescan
2594 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
2595 lappend disable_on_lock \
2596 {.vpane.lower.commarea.buttons.rescan conf -state}
@@ -2985,9 +3011,9 @@ if {[is_enabled transport]} {
3011 bind . <$M1B-Key-P> do_push_anywhere
3012 }
3013
2988 -bind . <Key-F5> do_rescan
2989 -bind . <$M1B-Key-r> do_rescan
2990 -bind . <$M1B-Key-R> do_rescan
3014 +bind . <Key-F5> ui_do_rescan
3015 +bind . <$M1B-Key-r> ui_do_rescan
3016 +bind . <$M1B-Key-R> ui_do_rescan
3017 bind . <$M1B-Key-s> do_signoff
3018 bind . <$M1B-Key-S> do_signoff
3019 bind . <$M1B-Key-t> do_add_selection