{"thread":{"id":"50130","subject":"[PATCH 1/2] t5403: simplify by using a single repository","startedAt":"2018-12-29T21:38:08Z","lastAt":"2019-01-02T15:47:20Z","messageCount":3,"participants":["orgads@gmail.com","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"365977","messageId":"20181229213759.12878-1-orgads@gmail.com","threadId":"50130","inReplyTo":null,"subject":"[PATCH 1/2] t5403: simplify by using a single repository","fromName":"","fromEmail":"orgads@gmail.com","sentAt":"2018-12-29T21:37:58Z","receivedAt":"2018-12-29T21:38:08Z","isPatch":true,"sender":{"key":"orgads@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1246544?v=4"},"body":"From: Orgad Shaneh <orgads@gmail.com>\n\nThere is no strong reason to use separate clones to run\nthese tests; just use a single test repository prepared\nwith more modern test_commit shell helper function.\n\nWhile at it, replace three \"awk '{print $N}'\" on the same\nfile with shell built-in \"read\" into three variables.\n\nRevert d42ec126aa717d00549e387d5a95fd55683c2e2c which is a workaround for\nCygwin that is no longer needed.\n\nSigned-off-by: Orgad Shaneh <orgads@gmail.com>\n---\n t/t5403-post-checkout-hook.sh | 78 +++++++++++------------------------\n 1 file changed, 23 insertions(+), 55 deletions(-)\n\ndiff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\nindex fc898c9eac..1d15a1031f 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -7,82 +7,50 @@ 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-'\n-\n-for clone in 1 2; do\n-    cat >clone${clone}/.git/hooks/post-checkout <<'EOF'\n-#!/bin/sh\n-echo $@ > $GIT_DIR/post-checkout.args\n-EOF\n-    chmod u+x clone${clone}/.git/hooks/post-checkout\n-done\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+\tmkdir -p .git/hooks &&\n+\twrite_script .git/hooks/post-checkout <<-\\EOF &&\n+\techo \"$@\" >.git/post-checkout.args\n+\tEOF\n+\ttest_commit one &&\n+\ttest_commit two &&\n+\ttest_commit three\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+\ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n+\tgit checkout master &&\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-'\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+\ttest_when_finished \"rm -f .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+\ttest_when_finished \"rm -f .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+\ttest_when_finished \"rm -f .git/post-checkout.args\" &&\n+\tgit checkout master -- three.t &&\n+\tread old new flag <.git/post-checkout.args &&\n \ttest $old = $new && test $flag = 0\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-#!/bin/sh\n-echo $@ > $GIT_DIR/post-checkout.args\n-EOF\n-chmod +x templates/hooks/post-checkout\n-\n test_expect_success 'post-checkout hook is triggered by clone' '\n+\tmkdir -p templates/hooks &&\n+\twrite_script templates/hooks/post-checkout <<-\\EOF &&\n+\techo \"$@\" >$GIT_DIR/post-checkout.args\n+\tEOF\n \tgit clone --template=templates . clone3 &&\n \ttest -f clone3/.git/post-checkout.args\n '\n-fi\n \n test_done\n-- \n2.20.1\n\n"},{"id":"365978","messageId":"20181229213759.12878-2-orgads@gmail.com","threadId":"50130","inReplyTo":"20181229213759.12878-1-orgads@gmail.com","subject":"[PATCH 2/2] Rebase: Run post-checkout hook on checkout","fromName":"","fromEmail":"orgads@gmail.com","sentAt":"2018-12-29T21:37:59Z","receivedAt":"2018-12-29T21:38:10Z","isPatch":true,"sender":{"key":"orgads@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1246544?v=4"},"body":"From: Orgad Shaneh <orgads@gmail.com>\n\nThe scripted version of rebase used to run this hook on the initial\ncheckout. The transition to built-in introduced a regression.\n\nSigned-off-by: Orgad Shaneh <orgads@gmail.com>\n---\n builtin/rebase.c              | 12 ++++++++++--\n t/t5403-post-checkout-hook.sh | 20 ++++++++++++++++++++\n 2 files changed, 30 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex b5c99ec10c..8402765a79 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_POST_CHECKOUT_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_POST_CHECKOUT_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@@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n \t\t\t\t\t    getenv(GIT_REFLOG_ACTION_ENVIRONMENT),\n \t\t\t\t\t    options.switch_to);\n \t\t\t\tif (reset_head(&oid, \"checkout\",\n-\t\t\t\t\t       options.head_name, 0,\n+\t\t\t\t\t       options.head_name,\n+\t\t\t\t\t       RESET_HEAD_RUN_POST_CHECKOUT_HOOK,\n \t\t\t\t\t       NULL, buf.buf) < 0) {\n \t\t\t\t\tret = !!error(_(\"could not switch to \"\n \t\t\t\t\t\t\t\"%s\"),\n@@ -1539,7 +1546,8 @@ 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_POST_CHECKOUT_HOOK,\n+\t\t       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 1d15a1031f..a539ffc080 100755\n--- a/t/t5403-post-checkout-hook.sh\n+++ b/t/t5403-post-checkout-hook.sh\n@@ -13,6 +13,8 @@ test_expect_success setup '\n \tEOF\n \ttest_commit one &&\n \ttest_commit two &&\n+\ttest_commit rebase-on-me &&\n+\tgit reset --hard HEAD^ &&\n \ttest_commit three\n '\n \n@@ -44,6 +46,24 @@ 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+\ttest_when_finished \"rm -f .git/post-checkout.args\" &&\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+\ttest_when_finished \"rm -f .git/post-checkout.args\" &&\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 test_expect_success 'post-checkout hook is triggered by clone' '\n \tmkdir -p templates/hooks &&\n \twrite_script templates/hooks/post-checkout <<-\\EOF &&\n-- \n2.20.1\n\n"},{"id":"366042","messageId":"nycvar.QRO.7.76.6.1901021646060.45@tvgsbejvaqbjf.bet","threadId":"50130","inReplyTo":"20181229213759.12878-2-orgads@gmail.com","subject":"Re: [PATCH 2/2] Rebase: Run post-checkout hook on checkout","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2019-01-02T15:47:16Z","receivedAt":"2019-01-02T15:47:20Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Orgad,\n\nOn Sat, 29 Dec 2018, orgads@gmail.com wrote:\n\n> From: Orgad Shaneh <orgads@gmail.com>\n> \n> The scripted version of rebase used to run this hook on the initial\n> checkout. The transition to built-in introduced a regression.\n> \n> Signed-off-by: Orgad Shaneh <orgads@gmail.com>\n\nACK!\n\nFor lurkers: there was a \"pre-review\" at\nhttps://github.com/git-for-windows/git/pull/1992\n\nCiao,\nDscho\n\n> ---\n>  builtin/rebase.c              | 12 ++++++++++--\n>  t/t5403-post-checkout-hook.sh | 20 ++++++++++++++++++++\n>  2 files changed, 30 insertions(+), 2 deletions(-)\n> \n> diff --git a/builtin/rebase.c b/builtin/rebase.c\n> index b5c99ec10c..8402765a79 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_POST_CHECKOUT_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_POST_CHECKOUT_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> @@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)\n>  \t\t\t\t\t    getenv(GIT_REFLOG_ACTION_ENVIRONMENT),\n>  \t\t\t\t\t    options.switch_to);\n>  \t\t\t\tif (reset_head(&oid, \"checkout\",\n> -\t\t\t\t\t       options.head_name, 0,\n> +\t\t\t\t\t       options.head_name,\n> +\t\t\t\t\t       RESET_HEAD_RUN_POST_CHECKOUT_HOOK,\n>  \t\t\t\t\t       NULL, buf.buf) < 0) {\n>  \t\t\t\t\tret = !!error(_(\"could not switch to \"\n>  \t\t\t\t\t\t\t\"%s\"),\n> @@ -1539,7 +1546,8 @@ 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_POST_CHECKOUT_HOOK,\n> +\t\t       NULL, msg.buf))\n>  \t\tdie(_(\"Could not detach HEAD\"));\n>  \tstrbuf_release(&msg);\n>  \n> diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh\n> index 1d15a1031f..a539ffc080 100755\n> --- a/t/t5403-post-checkout-hook.sh\n> +++ b/t/t5403-post-checkout-hook.sh\n> @@ -13,6 +13,8 @@ test_expect_success setup '\n>  \tEOF\n>  \ttest_commit one &&\n>  \ttest_commit two &&\n> +\ttest_commit rebase-on-me &&\n> +\tgit reset --hard HEAD^ &&\n>  \ttest_commit three\n>  '\n>  \n> @@ -44,6 +46,24 @@ 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> +\ttest_when_finished \"rm -f .git/post-checkout.args\" &&\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> +\ttest_when_finished \"rm -f .git/post-checkout.args\" &&\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>  test_expect_success 'post-checkout hook is triggered by clone' '\n>  \tmkdir -p templates/hooks &&\n>  \twrite_script templates/hooks/post-checkout <<-\\EOF &&\n> -- \n> 2.20.1\n> \n> \n"}]}