git-gui: run post-checkout hook on checkout
git-gui is using "git-read-tree -u" for checkout which doesn't invoke the post-checkout hook as a plain git-checkout would. So git-gui must call the hook itself. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Jens Lehmann committed
Mar 30, 2009 at 21:46 UTC
c9498339a40566c736a85238c29fd45d63510abe
1 file changed
+39
-4
lib/checkout_op.tcl
+39
-4
@@ -9,6 +9,7 @@ field w_cons {}; # embedded console window object
9
field new_expr ; # expression the user saw/thinks this is
10
field new_hash ; # commit SHA-1 we are switching to
11
field new_ref ; # ref we are updating/creating
12
+field old_hash ; # commit SHA-1 that was checked out when we started
13
14
field parent_w .; # window that started us
15
field merge_type none; # type of merge to apply to existing branch
@@ -280,11 +281,11 @@ method _start_checkout {} {
281
282
# -- Our in memory state should match the repository.
283
#
283
- repository_state curType curHEAD curMERGE_HEAD
284
+ repository_state curType old_hash curMERGE_HEAD
285
if {[string match amend* $commit_type]
286
&& $curType eq {normal}
286
- && $curHEAD eq $HEAD} {
287
- } elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {
287
+ && $old_hash eq $HEAD} {
288
+ } elseif {$commit_type ne $curType || $HEAD ne $old_hash} {
289
info_popup [mc "Last scanned state does not match repository state.
290
291
Another Git program has modified this repository since the last scan. A rescan must be performed before the current branch can be changed.
@@ -297,7 +298,7 @@ The rescan will be automatically started now.
298
return
299
}
300
300
- if {$curHEAD eq $new_hash} {
301
+ if {$old_hash eq $new_hash} {
302
_after_readtree $this
303
} elseif {[is_config_true gui.trustmtime]} {
304
_readtree $this
@@ -453,13 +454,47 @@ method _after_readtree {} {
454
If you wanted to be on a branch, create one now starting from 'This Detached Checkout'."]
455
}
456
457
+ # -- Run the post-checkout hook.
458
+ #
459
+ set fd_ph [githook_read post-checkout $old_hash $new_hash 1]
460
+ if {$fd_ph ne {}} {
461
+ global pch_error
462
+ set pch_error {}
463
+ fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
464
+ fileevent $fd_ph readable [cb _postcheckout_wait $fd_ph]
465
+ } else {
466
+ _update_repo_state $this
467
+ }
468
+}
469
+
470
+method _postcheckout_wait {fd_ph} {
471
+ global pch_error
472
+
473
+ append pch_error [read $fd_ph]
474
+ fconfigure $fd_ph -blocking 1
475
+ if {[eof $fd_ph]} {
476
+ if {[catch {close $fd_ph}]} {
477
+ hook_failed_popup post-checkout $pch_error 0
478
+ }
479
+ unset pch_error
480
+ _update_repo_state $this
481
+ return
482
+ }
483
+ fconfigure $fd_ph -blocking 0
484
+}
485
+
486
+method _update_repo_state {} {
487
# -- Update our repository state. If we were previously in
488
# amend mode we need to toss the current buffer and do a
489
# full rescan to update our file lists. If we weren't in
490
# amend mode our file lists are accurate and we can avoid
491
# the rescan.
492
#
493
+ global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
494
+ global ui_comm
495
+
496
unlock_index
497
+ set name [_name $this]
498
set selected_commit_type new
499
if {[string match amend* $commit_type]} {
500
$ui_comm delete 0.0 end