@@ -9,6 +9,7 @@ field w_cons {}; # embedded console window object
9
9
field new_expr ; # expression the user saw/thinks this is
10
10
field new_hash ; # commit SHA-1 we are switching to
11
11
field new_ref ; # ref we are updating/creating
12
+ field old_hash ; # commit SHA-1 that was checked out when we started
12
13
13
14
field parent_w .; # window that started us
14
15
field merge_type none; # type of merge to apply to existing branch
@@ -280,11 +281,11 @@ method _start_checkout {} {
280
281
281
282
# -- Our in memory state should match the repository.
282
283
#
283
- repository_state curType curHEAD curMERGE_HEAD
284
+ repository_state curType old_hash curMERGE_HEAD
284
285
if {[string match amend* $commit_type ]
285
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 } {
288
289
info_popup [mc " Last scanned state does not match repository state.
289
290
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.
297
298
return
298
299
}
299
300
300
- if {$curHEAD eq $new_hash } {
301
+ if {$old_hash eq $new_hash } {
301
302
_after_readtree $this
302
303
} elseif {[is_config_true gui.trustmtime]} {
303
304
_readtree $this
@@ -453,13 +454,47 @@ method _after_readtree {} {
453
454
If you wanted to be on a branch, create one now starting from 'This Detached Checkout'." ]
454
455
}
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 {} {
456
487
# -- Update our repository state. If we were previously in
457
488
# amend mode we need to toss the current buffer and do a
458
489
# full rescan to update our file lists. If we weren't in
459
490
# amend mode our file lists are accurate and we can avoid
460
491
# the rescan.
461
492
#
493
+ global selected_commit_type commit_type HEAD MERGE_HEAD PARENT
494
+ global ui_comm
495
+
462
496
unlock_index
497
+ set name [_name $this ]
463
498
set selected_commit_type new
464
499
if {[string match amend* $commit_type ]} {
465
500
$ui_comm delete 0.0 end
0 commit comments