{"thread":{"id":"18648","subject":"[PATCH v2] git-gui: run post-checkout hook on checkout","startedAt":"2009-03-30T19:46:17Z","lastAt":"2009-03-30T19:46:17Z","messageCount":1,"participants":["Jens Lehmann"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"109939","messageId":"49D12189.5070409@web.de","threadId":"18648","inReplyTo":null,"subject":"[PATCH v2] git-gui: run post-checkout hook on checkout","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2009-03-30T19:46:17Z","receivedAt":"2009-03-30T19:46:17Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"git-gui is using \"git-read-tree -u\" for checkout which doesn't\ninvoke the post-checkout hook as a plain git-checkout would.\nSo git-gui must call the hook itself.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\n\nThanks to Shawn for the review of the first version, this one\ntries to address all the issues raised.\n\n\n git-gui/lib/checkout_op.tcl |   43 +++++++++++++++++++++++++++++++++++++++----\n 1 files changed, 39 insertions(+), 4 deletions(-)\n\ndiff --git a/git-gui/lib/checkout_op.tcl b/git-gui/lib/checkout_op.tcl\nindex caca888..9e7412c 100644\n--- a/git-gui/lib/checkout_op.tcl\n+++ b/git-gui/lib/checkout_op.tcl\n@@ -9,6 +9,7 @@ field w_cons   {}; # embedded console window object\n field new_expr   ; # expression the user saw/thinks this is\n field new_hash   ; # commit SHA-1 we are switching to\n field new_ref    ; # ref we are updating/creating\n+field old_hash   ; # commit SHA-1 that was checked out when we started\n \n field parent_w      .; # window that started us\n field merge_type none; # type of merge to apply to existing branch\n@@ -280,11 +281,11 @@ method _start_checkout {} {\n \n \t# -- Our in memory state should match the repository.\n \t#\n-\trepository_state curType curHEAD curMERGE_HEAD\n+\trepository_state curType old_hash curMERGE_HEAD\n \tif {[string match amend* $commit_type]\n \t\t&& $curType eq {normal}\n-\t\t&& $curHEAD eq $HEAD} {\n-\t} elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {\n+\t\t&& $old_hash eq $HEAD} {\n+\t} elseif {$commit_type ne $curType || $HEAD ne $old_hash} {\n \t\tinfo_popup [mc \"Last scanned state does not match repository state.\n \n Another Git program has modified this repository since the last scan.  A rescan must be performed before the current branch can be changed.\n@@ -297,7 +298,7 @@ The rescan will be automatically started now.\n \t\treturn\n \t}\n \n-\tif {$curHEAD eq $new_hash} {\n+\tif {$old_hash eq $new_hash} {\n \t\t_after_readtree $this\n \t} elseif {[is_config_true gui.trustmtime]} {\n \t\t_readtree $this\n@@ -453,13 +454,47 @@ method _after_readtree {} {\n If you wanted to be on a branch, create one now starting from 'This Detached Checkout'.\"]\n \t}\n \n+\t# -- Run the post-checkout hook.\n+\t#\n+\tset fd_ph [githook_read post-checkout $old_hash $new_hash 1]\n+\tif {$fd_ph ne {}} {\n+\t\tglobal pch_error\n+\t\tset pch_error {}\n+\t\tfconfigure $fd_ph -blocking 0 -translation binary -eofchar {}\n+\t\tfileevent $fd_ph readable [cb _postcheckout_wait $fd_ph]\n+\t} else {\n+\t\t_update_repo_state $this\n+\t}\n+}\n+\n+method _postcheckout_wait {fd_ph} {\n+\tglobal pch_error\n+\n+\tappend pch_error [read $fd_ph]\n+\tfconfigure $fd_ph -blocking 1\n+\tif {[eof $fd_ph]} {\n+\t\tif {[catch {close $fd_ph}]} {\n+\t\t\thook_failed_popup post-checkout $pch_error 0\n+\t\t}\n+\t\tunset pch_error\n+\t\t_update_repo_state $this\n+\t\treturn\n+\t}\n+\tfconfigure $fd_ph -blocking 0\n+}\n+\n+method _update_repo_state {} {\n \t# -- Update our repository state.  If we were previously in\n \t#    amend mode we need to toss the current buffer and do a\n \t#    full rescan to update our file lists.  If we weren't in\n \t#    amend mode our file lists are accurate and we can avoid\n \t#    the rescan.\n \t#\n+\tglobal selected_commit_type commit_type HEAD MERGE_HEAD PARENT\n+\tglobal ui_comm\n+\n \tunlock_index\n+\tset name [_name $this]\n \tset selected_commit_type new\n \tif {[string match amend* $commit_type]} {\n \t\t$ui_comm delete 0.0 end\n-- \n1.6.2.1.414.g2daa3\n"}]}