{"thread":{"id":"50085","subject":"[PATCH 1/2] t5403: Refactor","startedAt":"2018-12-20T21:56:11Z","lastAt":"2018-12-20T21:56:15Z","messageCount":2,"participants":["orgads@gmail.com"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"365707","messageId":"20181220215559.22454-1-orgads@gmail.com","threadId":"50085","inReplyTo":null,"subject":"[PATCH 1/2] t5403: Refactor","fromName":"","fromEmail":"orgads@gmail.com","sentAt":"2018-12-20T21:55:58Z","receivedAt":"2018-12-20T21:56:11Z","isPatch":true,"sender":{"key":"orgads@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1246544?v=4"},"body":"From: Orgad Shaneh <orgads@gmail.com>\n\n* Replace multiple clones and commits by test_commits.\n* Replace 3 invocations of awk by read.\n\nSigned-off-by: Orgad Shaneh <orgads@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 55 ++++++++++++-----------------------\n 1 file changed, 18 insertions(+), 37 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex fc898c9eac..868d6f7272 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -7,67 +7,48 @@ test_description='Test the post-checkout hook.'\n . ./test-lib.sh\n \n test_expect_success setup '\n-\techo Data for commit0. >a &&\n-\techo Data for commit0. >b &&\n-\tgit update-index --add a &&\n-\tgit update-index --add b &&\n-\ttree0=$(git write-tree) &&\n-\tcommit0=$(echo setup | git commit-tree $tree0) &&\n-\tgit update-ref refs/heads/master $commit0 &&\n-\tgit clone ./. clone1 &&\n-\tgit clone ./. clone2 &&\n-\tGIT_DIR=clone2/.git git branch new2 &&\n-\techo Data for commit1. >clone2/b &&\n-\tGIT_DIR=clone2/.git git add clone2/b &&\n-\tGIT_DIR=clone2/.git git commit -m new2\n+\ttest_commit one &&\n+\ttest_commit two &&\n+\ttest_commit three three &&\n+\tmv .git/hooks-disabled .git/hooks\n '\n \n-for clone in 1 2; do\n-    cat >clone${clone}/.git/hooks/post-checkout <<'EOF'\n+cat >.git/hooks/post-checkout <<'EOF'\n #!/bin/sh\n-echo $@ > $GIT_DIR/post-checkout.args\n+echo $@ > .git/post-checkout.args\n EOF\n-    chmod u+x clone${clone}/.git/hooks/post-checkout\n-done\n+chmod u+x .git/hooks/post-checkout\n \n test_expect_success 'post-checkout runs as expected ' '\n-\tGIT_DIR=clone1/.git git checkout master &&\n-\ttest -e clone1/.git/post-checkout.args\n+\tgit checkout master &&\n+\ttest -e .git/post-checkout.args\n '\n \n test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '\n-\told=$(awk \"{print \\$1}\" clone1/.git/post-checkout.args) &&\n-\tnew=$(awk \"{print \\$2}\" clone1/.git/post-checkout.args) &&\n-\tflag=$(awk \"{print \\$3}\" clone1/.git/post-checkout.args) &&\n+\tread old new flag < .git/post-checkout.args &&\n \ttest $old = $new && test $flag = 1\n '\n \n test_expect_success 'post-checkout runs as expected ' '\n-\tGIT_DIR=clone1/.git git checkout master &&\n-\ttest -e clone1/.git/post-checkout.args\n+\tgit checkout master &&\n+\ttest -e .git/post-checkout.args\n '\n \n test_expect_success 'post-checkout args are correct with git checkout -b ' '\n-\tGIT_DIR=clone1/.git git checkout -b new1 &&\n-\told=$(awk \"{print \\$1}\" clone1/.git/post-checkout.args) &&\n-\tnew=$(awk \"{print \\$2}\" clone1/.git/post-checkout.args) &&\n-\tflag=$(awk \"{print \\$3}\" clone1/.git/post-checkout.args) &&\n+\tgit checkout -b new1 &&\n+\tread old new flag < .git/post-checkout.args &&\n \ttest $old = $new && test $flag = 1\n '\n \n test_expect_success 'post-checkout receives the right args with HEAD changed ' '\n-\tGIT_DIR=clone2/.git git checkout new2 &&\n-\told=$(awk \"{print \\$1}\" clone2/.git/post-checkout.args) &&\n-\tnew=$(awk \"{print \\$2}\" clone2/.git/post-checkout.args) &&\n-\tflag=$(awk \"{print \\$3}\" clone2/.git/post-checkout.args) &&\n+\tgit checkout two &&\n+\tread old new flag < .git/post-checkout.args &&\n \ttest $old != $new && test $flag = 1\n '\n \n test_expect_success 'post-checkout receives the right args when not switching branches ' '\n-\tGIT_DIR=clone2/.git git checkout master b &&\n-\told=$(awk \"{print \\$1}\" clone2/.git/post-checkout.args) &&\n-\tnew=$(awk \"{print \\$2}\" clone2/.git/post-checkout.args) &&\n-\tflag=$(awk \"{print \\$3}\" clone2/.git/post-checkout.args) &&\n+\tgit checkout master -- three &&\n+\tread old new flag < .git/post-checkout.args &&\n \ttest $old = $new && test $flag = 0\n '\n \n-- \n2.20.1\n\n"},{"id":"365708","messageId":"20181220215559.22454-2-orgads@gmail.com","threadId":"50085","inReplyTo":"20181220215559.22454-1-orgads@gmail.com","subject":"[PATCH 2/2] Rebase: Run post-checkout hook on checkout","fromName":"","fromEmail":"orgads@gmail.com","sentAt":"2018-12-20T21:55:59Z","receivedAt":"2018-12-20T21:56:15Z","isPatch":true,"sender":{"key":"orgads@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1246544?v=4"},"body":"From: Orgad Shaneh <orgads@gmail.com>\n\nSigned-off-by: Orgad Shaneh <orgads@gmail.com>\n---\n builtin/rebase.c              |  8 +++++++-\n t/t5403-post-checkout-hook.sh | 18 ++++++++++++++++++\n 2 files changed, 25 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex b5c99ec10c..78a09dcda2 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts)\n \n #define RESET_HEAD_DETACH (1<<0)\n #define RESET_HEAD_HARD (1<<1)\n+#define RESET_HEAD_RUN_HOOK (1<<2)\n \n static int reset_head(struct object_id *oid, const char *action,\n \t\t      const char *switch_to_branch, unsigned flags,\n@@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action,\n {\n \tunsigned detach_head = flags & RESET_HEAD_DETACH;\n \tunsigned reset_hard = flags & RESET_HEAD_HARD;\n+\tunsigned run_hook = flags & RESET_HEAD_RUN_HOOK;\n \tstruct object_id head_oid;\n \tstruct tree_desc desc[2] = { { NULL }, { NULL } };\n \tstruct lock_file lock = LOCK_INIT;\n@@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action,\n \t\t\tret = update_ref(reflog_head, \"HEAD\", oid, NULL, 0,\n \t\t\t\t\t UPDATE_REFS_MSG_ON_ERR);\n \t}\n+\tif (run_hook)\n+\t\trun_hook_le(NULL, \"post-checkout\",\n+\t\t\t    oid_to_hex(orig ? orig : &null_oid),\n+\t\t\t    oid_to_hex(oid), \"1\", NULL);\n \n leave_reset_head:\n \tstrbuf_release(&msg);\n@@ -1539,7 +1545,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \tstrbuf_addf(&msg, \"%s: checkout %s\",\n \t\t    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);\n \tif (reset_head(&options.onto->object.oid, \"checkout\", NULL,\n-\t\t       RESET_HEAD_DETACH, NULL, msg.buf))\n+\t\t       RESET_HEAD_DETACH | RESET_HEAD_RUN_HOOK, NULL, msg.buf))\n \t\tdie(_(\"Could not detach HEAD\"));\n \tstrbuf_release(&msg);\n \ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex 868d6f7272..ed4cc6e945 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -9,6 +9,8 @@ test_description='Test the post-checkout hook.'\n test_expect_success setup '\n \ttest_commit one &&\n \ttest_commit two &&\n+\ttest_commit rebase-on-me &&\n+\tgit reset --hard HEAD^ &&\n \ttest_commit three three &&\n \tmv .git/hooks-disabled .git/hooks\n '\n@@ -52,6 +54,22 @@ test_expect_success 'post-checkout receives the right args when not switching br\n \ttest $old = $new && test $flag = 0\n '\n \n+test_expect_success 'post-checkout is triggered on rebase' '\n+\tgit checkout -b rebase-test master &&\n+\trm -f .git/post-checkout.args &&\n+\tgit rebase rebase-on-me &&\n+\tread old new flag < .git/post-checkout.args &&\n+\ttest $old != $new && test $flag = 1\n+'\n+\n+test_expect_success 'post-checkout is triggered on rebase with fast-forward' '\n+\tgit checkout -b ff-rebase-test rebase-on-me^ &&\n+\trm -f .git/post-checkout.args &&\n+\tgit rebase rebase-on-me &&\n+\tread old new flag < .git/post-checkout.args &&\n+\ttest $old != $new && test $flag = 1\n+'\n+\n if test \"$(git config --bool core.filemode)\" = true; then\n mkdir -p templates/hooks\n cat >templates/hooks/post-checkout <<'EOF'\n-- \n2.20.1\n\n"}]}