git-gui: Automatically update-index all included files before commit.
If the user has "Allow Partially Included Files" disabled (and most probably will as its the default setting) we should run update-index on every included file before commit to make sure that any changes made by the user since the last rescan will still be part of this commit. If we don't update-index every modified file the user will likely become confused when part of their changes were committed and other parts weren't; and those other parts won't show up until a later rescan occurs. Since we don't rescan immediately after a commit this may be a while. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 15, 2006 at 18:06 UTC
bbe3b3b9b93763ff4eff4fbb638b1c6a4bed8c95
1 file changed
+66
-35
git-gui
+66
-35
@@ -420,7 +420,7 @@ proc rescan_done {fd buf after} {
420
display_all_files
421
422
if {$repo_config(gui.partialinclude) ne {true}} {
423
- set pathList [list]
423
+ set pathList [list]
424
foreach path [array names file_states] {
425
switch -- [lindex $file_states($path) 0] {
426
AM -
@@ -703,9 +703,7 @@ proc load_last_commit {} {
703
}
704
705
proc commit_tree {} {
706
- global tcl_platform HEAD gitdir commit_type file_states
707
- global pch_error
708
- global ui_status_value ui_comm
706
+ global HEAD commit_type file_states ui_comm repo_config
707
708
if {![lock_index update]} return
709
@@ -719,8 +717,10 @@ proc commit_tree {} {
717
error_popup {Last scanned state does not match repository state.
718
719
Its highly likely that another Git program modified the
722
-repository since our last scan. A rescan is required
720
+repository since the last scan. A rescan is required
721
before committing.
722
+
723
+A rescan will be automatically started now.
724
}
725
unlock_index
726
rescan {set ui_status_value {Ready.}}
@@ -731,8 +731,7 @@ before committing.
731
#
732
set files_ready 0
733
foreach path [array names file_states] {
734
- set s $file_states($path)
735
- switch -glob -- [lindex $s 0] {
734
+ switch -glob -- [lindex $file_states($path) 0] {
735
_? {continue}
736
A? -
737
D? -
@@ -779,10 +778,39 @@ A good commit message has the following format:
778
return
779
}
780
782
- # -- Ask the pre-commit hook for the go-ahead.
781
+ # -- Update included files if partialincludes are off.
782
#
783
+ if {$repo_config(gui.partialinclude) ne {true}} {
784
+ set pathList [list]
785
+ foreach path [array names file_states] {
786
+ switch -glob -- [lindex $file_states($path) 0] {
787
+ A? -
788
+ M? {lappend pathList $path}
789
+ }
790
+ }
791
+ if {$pathList ne {}} {
792
+ unlock_index
793
+ update_index \
794
+ "Updating included files" \
795
+ $pathList \
796
+ [concat {lock_index update;} \
797
+ [list commit_prehook $curHEAD $msg]]
798
+ return
799
+ }
800
+ }
801
+
802
+ commit_prehook $curHEAD $msg
803
+}
804
+
805
+proc commit_prehook {curHEAD msg} {
806
+ global tcl_platform gitdir ui_status_value pch_error
807
+
808
+ # On Cygwin [file executable] might lie so we need to ask
809
+ # the shell if the hook is executable. Yes that's annoying.
810
+
811
set pchook [file join $gitdir hooks pre-commit]
785
- if {$tcl_platform(platform) eq {windows} && [file isfile $pchook]} {
812
+ if {$tcl_platform(platform) eq {windows}
813
+ && [file isfile $pchook]} {
814
set pchook [list sh -c [concat \
815
"if test -x \"$pchook\";" \
816
"then exec \"$pchook\" 2>&1;" \
@@ -790,21 +818,19 @@ A good commit message has the following format:
818
} elseif {[file executable $pchook]} {
819
set pchook [list $pchook |& cat]
820
} else {
793
- set pchook {}
794
- }
795
- if {$pchook ne {}} {
796
- set ui_status_value {Calling pre-commit hook...}
797
- set pch_error {}
798
- set fd_ph [open "| $pchook" r]
799
- fconfigure $fd_ph -blocking 0 -translation binary
800
- fileevent $fd_ph readable \
801
- [list commit_stage1 $fd_ph $curHEAD $msg]
802
- } else {
803
- commit_stage2 $curHEAD $msg
821
+ commit_writetree $curHEAD $msg
822
+ return
823
}
824
+
825
+ set ui_status_value {Calling pre-commit hook...}
826
+ set pch_error {}
827
+ set fd_ph [open "| $pchook" r]
828
+ fconfigure $fd_ph -blocking 0 -translation binary
829
+ fileevent $fd_ph readable \
830
+ [list commit_prehook_wait $fd_ph $curHEAD $msg]
831
}
832
807
-proc commit_stage1 {fd_ph curHEAD msg} {
833
+proc commit_prehook_wait {fd_ph curHEAD msg} {
834
global pch_error ui_status_value
835
836
append pch_error [read $fd_ph]
@@ -815,25 +841,24 @@ proc commit_stage1 {fd_ph curHEAD msg} {
841
hook_failed_popup pre-commit $pch_error
842
unlock_index
843
} else {
818
- commit_stage2 $curHEAD $msg
844
+ commit_writetree $curHEAD $msg
845
}
846
set pch_error {}
821
- } else {
822
- fconfigure $fd_ph -blocking 0
847
+ return
848
}
849
+ fconfigure $fd_ph -blocking 0
850
}
851
826
-proc commit_stage2 {curHEAD msg} {
852
+proc commit_writetree {curHEAD msg} {
853
global ui_status_value
854
829
- # -- Write the tree in the background.
830
- #
855
set ui_status_value {Committing changes...}
856
set fd_wt [open "| git write-tree" r]
833
- fileevent $fd_wt readable [list commit_stage3 $fd_wt $curHEAD $msg]
857
+ fileevent $fd_wt readable \
858
+ [list commit_committree $fd_wt $curHEAD $msg]
859
}
860
836
-proc commit_stage3 {fd_wt curHEAD msg} {
861
+proc commit_committree {fd_wt curHEAD msg} {
862
global single_commit gitdir HEAD PARENT commit_type tcl_platform
863
global ui_status_value ui_comm
864
global file_states selected_paths
@@ -1252,14 +1277,20 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
1277
set path [lindex $pathList $update_index_cp]
1278
incr update_index_cp
1279
1255
- switch -- [lindex $file_states($path) 0] {
1256
- AM -
1257
- _O {set new A*}
1258
- _M -
1259
- MM {set new M*}
1280
+ switch -glob -- [lindex $file_states($path) 0] {
1281
AD -
1282
+ MD -
1283
_D {set new D*}
1262
- default {continue}
1284
+
1285
+ _M -
1286
+ MM -
1287
+ M_ {set new M*}
1288
+
1289
+ _O -
1290
+ AM -
1291
+ A_ {set new A*}
1292
+
1293
+ ?? {continue}
1294
}
1295
1296
puts -nonewline $fd $path