[PATCH 1/2] t5403: simplify by using a single repository
From: Orgad Shaneh There is no strong reason to use separate clones to run these tests; just use a single test repository prepared with more modern test_commit shell helper function. While at it, replace three "awk '{print $N}'" on the same file with shell built-in "read" into three variables. Revert d42ec126aa717d00549e387d5a95fd55683c2e2c which is a workaround for Cygwin that is no longer needed. Signed-off-by: Orgad Shaneh --- t/t5403-post-checkout-hook.sh | 78 +++ 1 file changed, 23 insertions(+), 55 deletions(-) diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index fc898c9eac..1d15a1031f 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,82 +7,50 @@ test_description='Test the post-checkout hook.' . ./test-lib.sh test_expect_success setup ' - echo Data for commit0. >a && - echo Data for commit0. >b && - git update-index --add a && - git update-index --add b && - tree0=$(git write-tree) && - commit0=$(echo setup | git commit-tree $tree0) && - git update-ref refs/heads/master $commit0 && - git clone ./. clone1 && - git clone ./. clone2 && - GIT_DIR=clone2/.git git branch new2 && - echo Data for commit1. >clone2/b && - GIT_DIR=clone2/.git git add clone2/b && - GIT_DIR=clone2/.git git commit -m new2 -' - -for clone in 1 2; do -cat >clone${clone}/.git/hooks/post-checkout <<'EOF' -#!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args -EOF -chmod u+x clone${clone}/.git/hooks/post-checkout -done - -test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + mkdir -p .git/hooks && + write_script .git/hooks/post-checkout <<-\EOF && + echo "$@" >.git/post-checkout.args + EOF + test_commit one && + test_commit two && + test_commit three ' test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + test_when_finished "rm -f .git/post-checkout.args" && + git checkout master && + read old new flag <.git/post-checkout.args && test $old = $new && test $flag = 1 ' -test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args -' - test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + test_when_finished "rm -f .git/post-checkout.args" && + git checkout -b new1 && + read old new flag <.git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + test_when_finished "rm -f .git/post-checkout.args" && + git checkout two && + read old new flag <.git/post-checkout.args && test $old != $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + test_when_finished "rm -f .git/post-checkout.args" && + git checkout master -- three.t && + read old new flag <.git/post-checkout.args && test $old = $new && test $flag = 0 ' -if test "$(git config --bool core.filemode)" = true; then -mkdir -p templates/hooks -cat >templates/hooks/post-checkout <<'EOF' -#!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args -EOF -chmod +x templates/hooks/post-checkout - test_expect_success 'post-checkout hook is triggered by clone' ' + mkdir -p templates/hooks && + write_script templates/hooks/post-checkout <<-\EOF && + echo "$@" >$GIT_DIR/post-checkout.args + EOF git clone --template=templates . clone3 && test -f clone3/.git/post-checkout.args ' -fi test_done -- 2.20.1
[PATCH 2/2] Rebase: Run post-checkout hook on checkout
From: Orgad Shaneh The scripted version of rebase used to run this hook on the initial checkout. The transition to built-in introduced a regression. Signed-off-by: Orgad Shaneh --- builtin/rebase.c | 12 ++-- t/t5403-post-checkout-hook.sh | 20 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec10c..8402765a79 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action, { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action, ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); leave_reset_head: strbuf_release(&msg); @@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.switch_to); if (reset_head(&oid, "checkout", - options.head_name, 0, + options.head_name, + RESET_HEAD_RUN_POST_CHECKOUT_HOOK, NULL, buf.buf) < 0) { ret = !!error(_("could not switch to " "%s"), @@ -1539,7 +1546,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_HEAD_RUN_POST_CHECKOUT_HOOK, + NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 1d15a1031f..a539ffc080 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -13,6 +13,8 @@ test_expect_success setup ' EOF test_commit one && test_commit two && + test_commit rebase-on-me && + git reset --hard HEAD^ && test_commit three ' @@ -44,6 +46,24 @@ test_expect_success 'post-checkout receives the right args when not switching br test $old = $new && test $flag = 0 ' +test_expect_success 'post-checkout is triggered on rebase' ' + test_when_finished "rm -f .git/post-checkout.args" && + git checkout -b rebase-test master && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag <.git/post-checkout.args && + test $old != $new && test $flag = 1 +' + +test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' + test_when_finished "rm -f .git/post-checkout.args" && + git checkout -b ff-rebase-test rebase-on-me^ && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag <.git/post-checkout.args && + test $old != $new && test $flag = 1 +' + test_expect_success 'post-checkout hook is triggered by clone' ' mkdir -p templates/hooks && write_script templates/hooks/post-checkout <<-\EOF && -- 2.20.1
[PATCH 1/2] t5403: Refactor
From: Orgad Shaneh * Replace multiple clones and commits by test_commits. * Replace 3 invocations of awk by read. Signed-off-by: Orgad Shaneh --- t/t5403-post-checkout-hook.sh | 80 +-- 1 file changed, 29 insertions(+), 51 deletions(-) diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index fc898c9eac..9f9a5163c5 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,77 +7,55 @@ test_description='Test the post-checkout hook.' . ./test-lib.sh test_expect_success setup ' - echo Data for commit0. >a && - echo Data for commit0. >b && - git update-index --add a && - git update-index --add b && - tree0=$(git write-tree) && - commit0=$(echo setup | git commit-tree $tree0) && - git update-ref refs/heads/master $commit0 && - git clone ./. clone1 && - git clone ./. clone2 && - GIT_DIR=clone2/.git git branch new2 && - echo Data for commit1. >clone2/b && - GIT_DIR=clone2/.git git add clone2/b && - GIT_DIR=clone2/.git git commit -m new2 -' - -for clone in 1 2; do -cat >clone${clone}/.git/hooks/post-checkout <<'EOF' -#!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args -EOF -chmod u+x clone${clone}/.git/hooks/post-checkout -done - -test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + mv .git/hooks-disabled .git/hooks && + write_script .git/hooks/post-checkout <<-\EOF && + echo $@ >.git/post-checkout.args + EOF + test_commit one && + test_commit two && + test_commit three three ' test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new && test $flag = 1 + git checkout master && + test -e .git/post-checkout.args && + read old new flag <.git/post-checkout.args && + test $old = $new && test $flag = 1 && + rm -f .git/post-checkout.args ' test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args && + rm -f .git/post-checkout.args ' test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new && test $flag = 1 + git checkout -b new1 && + read old new flag <.git/post-checkout.args && + test $old = $new && test $flag = 1 && + rm -f .git/post-checkout.args ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old != $new && test $flag = 1 + git checkout two && + read old new flag <.git/post-checkout.args && + test $old != $new && test $flag = 1 && + rm -f .git/post-checkout.args ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old = $new && test $flag = 0 + git checkout master -- three && + read old new flag <.git/post-checkout.args && + test $old = $new && test $flag = 0 && + rm -f .git/post-checkout.args ' if test "$(git config --bool core.filemode)" = true; then mkdir -p templates/hooks -cat >templates/hooks/post-checkout <<'EOF' -#!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args +write_script templates/hooks/post-checkout <<-\EOF +echo $@ >$GIT_DIR/post-checkout.args EOF -chmod +x templates/hooks/post-checkout test_expect_success 'post-checkout hook is triggered by clone' ' git clone --template=templates . clone3 && -- 2.20.1
[PATCH 2/2] Rebase: Run post-checkout hook on checkout
From: Orgad Shaneh Signed-off-by: Orgad Shaneh --- builtin/rebase.c | 11 +-- t/t5403-post-checkout-hook.sh | 20 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec10c..7f7a2c738e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_HOOK (1<<2) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action, { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_HOOK; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action, ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); leave_reset_head: strbuf_release(&msg); @@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.switch_to); if (reset_head(&oid, "checkout", - options.head_name, 0, + options.head_name, + RESET_HEAD_RUN_HOOK, NULL, buf.buf) < 0) { ret = !!error(_("could not switch to " "%s"), @@ -1539,7 +1546,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_HEAD_RUN_HOOK, NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 9f9a5163c5..5b4e582caa 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -13,6 +13,8 @@ test_expect_success setup ' EOF test_commit one && test_commit two && + test_commit rebase-on-me && + git reset --hard HEAD^ && test_commit three three ' @@ -51,6 +53,24 @@ test_expect_success 'post-checkout receives the right args when not switching br rm -f .git/post-checkout.args ' +test_expect_success 'post-checkout is triggered on rebase' ' + git checkout -b rebase-test master && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 && + rm -f .git/post-checkout.args +' + +test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' + git checkout -b ff-rebase-test rebase-on-me^ && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 && + rm -f .git/post-checkout.args +' + if test "$(git config --bool core.filemode)" = true; then mkdir -p templates/hooks write_script templates/hooks/post-checkout <<-\EOF -- 2.20.1
[PATCH] Rebase: Run post-checkout hook on checkout
From: Orgad Shaneh Signed-off-by: Orgad Shaneh --- builtin/rebase.c | 11 +-- t/t5403-post-checkout-hook.sh | 20 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec10c..7f7a2c738e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_HOOK (1<<2) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action, { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_HOOK; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action, ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); leave_reset_head: strbuf_release(&msg); @@ -1465,7 +1471,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.switch_to); if (reset_head(&oid, "checkout", - options.head_name, 0, + options.head_name, + RESET_HEAD_RUN_HOOK, NULL, buf.buf) < 0) { ret = !!error(_("could not switch to " "%s"), @@ -1539,7 +1546,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_HEAD_RUN_HOOK, NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 9f9a5163c5..5b4e582caa 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -13,6 +13,8 @@ test_expect_success setup ' EOF test_commit one && test_commit two && + test_commit rebase-on-me && + git reset --hard HEAD^ && test_commit three three ' @@ -51,6 +53,24 @@ test_expect_success 'post-checkout receives the right args when not switching br rm -f .git/post-checkout.args ' +test_expect_success 'post-checkout is triggered on rebase' ' + git checkout -b rebase-test master && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 && + rm -f .git/post-checkout.args +' + +test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' + git checkout -b ff-rebase-test rebase-on-me^ && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 && + rm -f .git/post-checkout.args +' + if test "$(git config --bool core.filemode)" = true; then mkdir -p templates/hooks write_script templates/hooks/post-checkout <<-\EOF -- 2.20.1
[PATCH 2/2] Rebase: Run post-checkout hook on checkout
From: Orgad Shaneh Signed-off-by: Orgad Shaneh --- builtin/rebase.c | 8 +++- t/t5403-post-checkout-hook.sh | 18 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec10c..78a09dcda2 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_HOOK (1<<2) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action, { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_HOOK; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action, ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); leave_reset_head: strbuf_release(&msg); @@ -1539,7 +1545,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_HEAD_RUN_HOOK, NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 868d6f7272..ed4cc6e945 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -9,6 +9,8 @@ test_description='Test the post-checkout hook.' test_expect_success setup ' test_commit one && test_commit two && + test_commit rebase-on-me && + git reset --hard HEAD^ && test_commit three three && mv .git/hooks-disabled .git/hooks ' @@ -52,6 +54,22 @@ test_expect_success 'post-checkout receives the right args when not switching br test $old = $new && test $flag = 0 ' +test_expect_success 'post-checkout is triggered on rebase' ' + git checkout -b rebase-test master && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 +' + +test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' + git checkout -b ff-rebase-test rebase-on-me^ && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 +' + if test "$(git config --bool core.filemode)" = true; then mkdir -p templates/hooks cat >templates/hooks/post-checkout <<'EOF' -- 2.20.1
[PATCH 1/2] t5403: Refactor
From: Orgad Shaneh * Replace multiple clones and commits by test_commits. * Replace 3 invocations of awk by read. Signed-off-by: Orgad Shaneh --- t/t5403-post-checkout-hook.sh | 55 --- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index fc898c9eac..868d6f7272 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,67 +7,48 @@ test_description='Test the post-checkout hook.' . ./test-lib.sh test_expect_success setup ' - echo Data for commit0. >a && - echo Data for commit0. >b && - git update-index --add a && - git update-index --add b && - tree0=$(git write-tree) && - commit0=$(echo setup | git commit-tree $tree0) && - git update-ref refs/heads/master $commit0 && - git clone ./. clone1 && - git clone ./. clone2 && - GIT_DIR=clone2/.git git branch new2 && - echo Data for commit1. >clone2/b && - GIT_DIR=clone2/.git git add clone2/b && - GIT_DIR=clone2/.git git commit -m new2 + test_commit one && + test_commit two && + test_commit three three && + mv .git/hooks-disabled .git/hooks ' -for clone in 1 2; do -cat >clone${clone}/.git/hooks/post-checkout <<'EOF' +cat >.git/hooks/post-checkout <<'EOF' #!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args +echo $@ > .git/post-checkout.args EOF -chmod u+x clone${clone}/.git/hooks/post-checkout -done +chmod u+x .git/hooks/post-checkout test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args ' test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args ' test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + git checkout -b new1 && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + git checkout two && + read old new flag < .git/post-checkout.args && test $old != $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + git checkout master -- three && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 0 ' -- 2.20.1
[PATCH 1/2] t5403: Refactor
From: Orgad Shaneh * Replace multiple clones and commits by test_commits. * Replace 3 invocations of awk by read. Signed-off-by: Orgad Shaneh --- t/t5403-post-checkout-hook.sh | 55 --- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index fc898c9eac..7e941537f9 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,67 +7,48 @@ test_description='Test the post-checkout hook.' . ./test-lib.sh test_expect_success setup ' - echo Data for commit0. >a && - echo Data for commit0. >b && - git update-index --add a && - git update-index --add b && - tree0=$(git write-tree) && - commit0=$(echo setup | git commit-tree $tree0) && - git update-ref refs/heads/master $commit0 && - git clone ./. clone1 && - git clone ./. clone2 && - GIT_DIR=clone2/.git git branch new2 && - echo Data for commit1. >clone2/b && - GIT_DIR=clone2/.git git add clone2/b && - GIT_DIR=clone2/.git git commit -m new2 + test_commit one && +test_commit two && +test_commit three three && +mv .git/hooks-disabled .git/hooks ' -for clone in 1 2; do -cat >clone${clone}/.git/hooks/post-checkout <<'EOF' +cat >.git/hooks/post-checkout <<'EOF' #!/bin/sh -echo $@ > $GIT_DIR/post-checkout.args +echo $@ > .git/post-checkout.args EOF -chmod u+x clone${clone}/.git/hooks/post-checkout -done +chmod u+x .git/hooks/post-checkout test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args ' test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + git checkout master && + test -e .git/post-checkout.args ' test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + git checkout -b new1 && +read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + git checkout two && +read old new flag < .git/post-checkout.args && test $old != $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + git checkout master -- three && +read old new flag < .git/post-checkout.args && test $old = $new && test $flag = 0 ' -- 2.20.1
[PATCH 2/2] Rebase: Run post-checkout hook on checkout
From: Orgad Shaneh Signed-off-by: Orgad Shaneh --- builtin/rebase.c | 8 +++- t/t5403-post-checkout-hook.sh | 18 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index b5c99ec10c..78a09dcda2 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -530,6 +530,7 @@ static int run_specific_rebase(struct rebase_options *opts) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) +#define RESET_HEAD_RUN_HOOK (1<<2) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -537,6 +538,7 @@ static int reset_head(struct object_id *oid, const char *action, { unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; + unsigned run_hook = flags & RESET_HEAD_RUN_HOOK; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -636,6 +638,10 @@ static int reset_head(struct object_id *oid, const char *action, ret = update_ref(reflog_head, "HEAD", oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); } + if (run_hook) + run_hook_le(NULL, "post-checkout", + oid_to_hex(orig ? orig : &null_oid), + oid_to_hex(oid), "1", NULL); leave_reset_head: strbuf_release(&msg); @@ -1539,7 +1545,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) strbuf_addf(&msg, "%s: checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); if (reset_head(&options.onto->object.oid, "checkout", NULL, - RESET_HEAD_DETACH, NULL, msg.buf)) + RESET_HEAD_DETACH | RESET_HEAD_RUN_HOOK, NULL, msg.buf)) die(_("Could not detach HEAD")); strbuf_release(&msg); diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 7e941537f9..de9c7fb871 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -9,6 +9,8 @@ test_description='Test the post-checkout hook.' test_expect_success setup ' test_commit one && test_commit two && +test_commit rebase-on-me && +git reset --hard HEAD^ && test_commit three three && mv .git/hooks-disabled .git/hooks ' @@ -52,6 +54,22 @@ test_expect_success 'post-checkout receives the right args when not switching br test $old = $new && test $flag = 0 ' +test_expect_success 'post-checkout is triggered on rebase' ' + git checkout -b rebase-test master && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 +' + +test_expect_success 'post-checkout is triggered on rebase with fast-forward' ' + git checkout -b ff-rebase-test rebase-on-me^ && + rm -f .git/post-checkout.args && + git rebase rebase-on-me && + read old new flag < .git/post-checkout.args && + test $old != $new && test $flag = 1 +' + if test "$(git config --bool core.filemode)" = true; then mkdir -p templates/hooks cat >templates/hooks/post-checkout <<'EOF' -- 2.20.1
[PATCH] doc: fix typos in release notes
From: Orgad Shaneh Signed-off-by: Orgad Shaneh --- Documentation/RelNotes/2.20.0.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/RelNotes/2.20.0.txt b/Documentation/RelNotes/2.20.0.txt index 4b546d025f..bc0f4e8237 100644 --- a/Documentation/RelNotes/2.20.0.txt +++ b/Documentation/RelNotes/2.20.0.txt @@ -56,7 +56,7 @@ UI, Workflows & Features * "git format-patch" learned new "--interdiff" and "--range-diff" options to explain the difference between this version and the - previous attempt in the cover letter (or after the tree-dashes as + previous attempt in the cover letter (or after the three-dashes as a comment). * "git mailinfo" used in "git am" learned to make a best-effort @@ -78,7 +78,7 @@ UI, Workflows & Features meaningfully large repository. The users will now see progress output. - * The minimum version of Windows supported by Windows port fo Git is + * The minimum version of Windows supported by Windows port of Git is now set to Vista. * The completion script (in contrib/) learned to complete a handful of -- 2.19.1
[PATCH] add a test for "describe --contains" with mixed tags
From: Orgad Shaneh If a repository has early lightweight tags and annotated tags later, running git describe --contains for an early commit used the annotated tag for reference, instead of the lightweight tag which was closer. This has been fixed in ef1e74065c19cc427c4a1b322154fd55d7a3588b, and regression was tweaked in 5554451de61cb90e530f30b96e62d455e1eff6a1. Add a test for that to avoid further regressions. Signed-off-by: Orgad Shaneh --- t/t6120-describe.sh | 16 1 file changed, 16 insertions(+) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 1c0e8659d..08427f4b5 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -340,4 +340,20 @@ test_expect_success ULIMIT_STACK_SIZE 'describe works in a deep repo' ' test_cmp expect actual ' +test_expect_success 'describe --contains for light before annotated' ' + test_tick && + git commit --allow-empty -m First && + test_tick && + git commit --allow-empty -m Second && + test_tick && + git commit --allow-empty -m Third && + test_tick && + git tag light-before-annotated HEAD^ && + test_tick && + git tag -a -m annotated annotated-after-light + +' + +check_describe light-before-annotated~1 --contains light-before-annotated~1 + test_done -- 2.15.0.rc2
[PATCH] add a test for "describe --contains" with mixed tags
From: Orgad Shaneh --- t/t6120-describe.sh | 16 1 file changed, 16 insertions(+) diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 1c0e865..08427f4 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -340,4 +340,20 @@ test_expect_success ULIMIT_STACK_SIZE 'describe works in a deep repo' ' test_cmp expect actual ' +test_expect_success 'describe --contains for light before annotated' ' + test_tick && + git commit --allow-empty -m First && + test_tick && + git commit --allow-empty -m Second && + test_tick && + git commit --allow-empty -m Third && + test_tick && + git tag light-before-annotated HEAD^ && + test_tick && + git tag -a -m annotated annotated-after-light + +' + +check_describe light-before-annotated~1 --contains light-before-annotated~1 + test_done -- 1.9.1
[PATCH] name-rev: Fix tag lookup on repository with mixed types of tags
From: Orgad Shaneh Commit 7550424804 (name-rev: include taggerdate in considering the best name) introduced a bug in name-rev. If a repository has both annotated and non-annotated tags, annotated tag will always win, even if it was created decades after the commit. Consider a repository that always used non-annotated tags, and at some point started using annotated tags - name-rev --tags will return the first annotated tags for all the old commits (in our repository it is followed by ~5067 for one commit, or by ~120^2~21^2~88^2~87 for another...). This is obviously not what the user expects. There was an attempt to fix this in ef1e74065, but it is not enough. The taggerdate should only be matched if *both tags* have it. Signed-off-by: Orgad Shaneh --- builtin/name-rev.c | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 9e088ebd11..dc9eaf21fa 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -35,7 +35,7 @@ static int is_better_name(struct rev_name *name, */ if (from_tag && name->from_tag) return (name->taggerdate > taggerdate || - (name->taggerdate == taggerdate && + ((taggerdate == TIME_MAX || name->taggerdate == taggerdate) && name->distance > distance)); /* @@ -53,7 +53,7 @@ static int is_better_name(struct rev_name *name, return name->distance > distance; /* ... or tiebreak to favor older date */ - if (name->taggerdate != taggerdate) + if (taggerdate != TIME_MAX && name->taggerdate != taggerdate) return name->taggerdate > taggerdate; /* keep the current one if we cannot decide */ @@ -90,7 +90,8 @@ static void name_rev(struct commit *commit, generation, distance, from_tag)) { copy_data: name->tip_name = tip_name; - name->taggerdate = taggerdate; + if (taggerdate != TIME_MAX) + name->taggerdate = taggerdate; name->generation = generation; name->distance = distance; name->from_tag = from_tag; -- 2.14.2.windows.3
[PATCH] name-rev: Fix tag lookup on repository with mixed types of tags
From: Orgad Shaneh Commit 7550424804 (name-rev: include taggerdate in considering the best name) introduced a bug in name-rev. If a repository has both annotated and non-annotated tags, annotated tag will always win, even if it was created decades after the commit. Consider a repository that always used non-annotated tags, and at some point started using annotated tags - name-rev --tags will return the first annotated tags for all the old commits (in our repository it is followed by ~5067 for one commit, or by ~120^2~21^2~88^2~87 for another...). This is obviously not what the user expects. The taggerdate should only be matched if *both tags* have it. --- builtin/name-rev.c | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 92a5d8a5d2..8f77023482 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -46,11 +46,13 @@ static void name_rev(struct commit *commit, commit->util = name; goto copy_data; } else if (name->taggerdate > taggerdate || - (name->taggerdate == taggerdate && + ((taggerdate == ULONG_MAX || name->taggerdate == taggerdate) && name->distance > distance)) { copy_data: name->tip_name = tip_name; - name->taggerdate = taggerdate; + if (taggerdate != ULONG_MAX) { + name->taggerdate = taggerdate; + } name->generation = generation; name->distance = distance; } else -- 2.13.1.windows.1.1.ga36e14b3aa
[PATCH v2] merge: Run commit-msg hook
From: Orgad Shaneh commit-msg is needed to either validate the commit message or edit it. Gerrit for instance uses this hook to append its Change-Id footer. The hook is installed on the user's machine, and it is expected to append the footer for each commit that the user creates. This is relevant to merge commit just like any other commit. Currently this hook is only called for simple commits, so Gerrit user that tries to push a merge commit has to amend it first in order to execute the hook that appends the footer. prepare-commit-msg hook is already called on merge, but commit-msg isn't. It looks like unlike pre-commit not being executed, which was a conscious decision[1], commit-msg was never considered. [1] http://thread.gmane.org/gmane.comp.version-control.git/151297/focus=151435 Signed-off-by: Orgad Shaneh --- Documentation/git-merge.txt | 6 +- builtin/merge.c | 7 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index b758d55..59508aa 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -11,7 +11,7 @@ SYNOPSIS [verse] 'git merge' [-n] [--stat] [--no-commit] [--squash] [--[no-]edit] [-s ] [-X ] [-S[]] - [--[no-]allow-unrelated-histories] + [--[no-]allow-unrelated-histories] [--no-verify] [--[no-]rerere-autoupdate] [-m ] [...] 'git merge' HEAD ... 'git merge' --abort @@ -87,6 +87,10 @@ invocations. The automated message can include the branch description. Allow the rerere mechanism to update the index with the result of auto-conflict resolution if possible. +--no-verify:: + This option bypasses the commit-msg hook. + See also linkgit:githooks[5]. + --abort:: Abort the current conflict resolution process, and try to reconstruct the pre-merge state. diff --git a/builtin/merge.c b/builtin/merge.c index b555a1b..30c03c8 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -51,7 +51,7 @@ static const char * const builtin_merge_usage[] = { static int show_diffstat = 1, shortlog_len = -1, squash; static int option_commit = 1; static int option_edit = -1; -static int allow_trivial = 1, have_message, verify_signatures; +static int allow_trivial = 1, have_message, verify_signatures, no_verify; static int overwrite_ignore = 1; static struct strbuf merge_msg = STRBUF_INIT; static struct strategy **use_strategies; @@ -228,6 +228,7 @@ static struct option builtin_merge_options[] = { { OPTION_STRING, 'S', "gpg-sign", &sign_commit, N_("key-id"), N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")), + OPT_BOOL(0, "no-verify", &no_verify, N_("bypass commit-msg hook")), OPT_END() }; @@ -809,6 +810,10 @@ static void prepare_to_commit(struct commit_list *remoteheads) if (launch_editor(git_path_merge_msg(), NULL, NULL)) abort_commit(remoteheads, NULL); } + if (!no_verify && + run_commit_hook(0 < option_edit, get_index_file(), "commit-msg", + git_path_merge_msg(), NULL)) + abort_commit(remoteheads, NULL); read_merge_msg(&msg); strbuf_stripspace(&msg, 0 < option_edit); if (!msg.len) -- 2.8.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2] commit: Fix description of no-verify
From: Orgad Shaneh include also commit-msg hook. This brings the short help in line with the documentation. Signed-off-by: Orgad Shaneh --- builtin/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/commit.c b/builtin/commit.c index 163dbca..2725712 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1616,7 +1616,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "interactive", &interactive, N_("interactively add files")), OPT_BOOL('p', "patch", &patch_interactive, N_("interactively add changes")), OPT_BOOL('o', "only", &only, N_("commit only specified files")), - OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit hook")), + OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")), OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be committed")), OPT_SET_INT(0, "short", &status_format, N_("show status concisely"), STATUS_FORMAT_SHORT), -- 2.8.1 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html