t5403.1: simplify commit creation
PATCH 1/3 t5403.1: simplify commit creation
--- t/t5403-post-checkout-hook.sh | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-)
t/t5403-post-checkout-hook.sh +2 -5
@@ -9,11 +9,8 @@ test_description='Test the post-checkout hook.' 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 add a b && + git commit -m setup && git clone ./. clone1 && git clone ./. clone2 && GIT_DIR=clone2/.git git branch new2 &&
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH 2/3 t5403: convert leading spaces to tabs
The first and last tests use tabs. The rest uses spaces. Convert all to tabs.
--- t/t5403-post-checkout-hook.sh | 46 ++++++++++++++++++++-------------------- 1 files changed, 23 insertions(+), 23 deletions(-)
t/t5403-post-checkout-hook.sh +23 -23
@@ -28,44 +28,44 @@ EOF done test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + GIT_DIR=clone1/.git git checkout master && + test -e clone1/.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) && - test $old = $new -a $flag = 1 + 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 -a $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_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 $old = $new -a $flag = 1 + 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 -a $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 $old != $new -a $flag = 1 + 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 -a $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 $old = $new -a $flag = 0 + 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 -a $flag = 0 ' if test "$(git config --bool core.filemode)" = true; then
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH 3/3 t5403: do not use access repos with GIT_DIR when worktree is involved
In reply to Nguyễn Thái Ngọc DuySetting GIT_DIR alone means worktree is current directory for legacy reasons. Avoid using that, instead go to the worktree and execute commands there.
The troublesome command is "GIT_DIR=clone2/.git git add clone2/b". The real worktree is clone2, but that command tells git worktree is $(pwd). What does user expect to add then? Should the new entry in index be "b" or "clone2/b"?
--- t/t5403-post-checkout-hook.sh | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-)
t/t5403-post-checkout-hook.sh +10 -7
@@ -13,10 +13,13 @@ test_expect_success setup ' git commit -m setup && 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 + ( + cd clone2 && + git branch new2 && + echo Data for commit1. >b && + git add b && + git commit -m new2 + ) ' for clone in 1 2; do
@@ -45,7 +48,7 @@ test_expect_success 'post-checkout runs as expected ' ' ' test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && + ( cd clone1 && 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) &&
@@ -53,7 +56,7 @@ test_expect_success 'post-checkout args are correct with git checkout -b ' ' ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && + ( cd clone2 && 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) &&
@@ -61,7 +64,7 @@ test_expect_success 'post-checkout receives the right args with HEAD changed ' ' ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && + ( cd clone2 && 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) &&
Signature · 1 line
1.7.3.1.256.g2539c.dirty
Re: [PATCH 3/3] t5403: do not use access repos with GIT_DIR when worktree is involved
Quoted 8 lines · Nguyễn Thái Ngọc Duy
Setting
GIT_DIRalone means worktree is current directory for legacy reasons. Avoid using that, instead go to the worktree and execute commands there.The troublesome command is "GIT_DIR=clone2/.git git add clone2/b". The real worktree is clone2, but that command tells git worktree is $(pwd). What does user expect to add then? Should the new entry in index be "b" or "clone2/b"?
There is no troublesomeness here, as the semantics has been clearly defined and (hopefully) stayed constant before the days when GIT_WORK_TREE was invented.
Assuming that there is no core.worktree in clone2/.git/config and there is no GIT_WORK_TREE environment variable, "GIT_DIR=$anything git add clone2/b" should add a path "clone2/b" to the index controlled by that $GIT_DIR no matter where $anything is.
I would like to find out the motivation behind this patch. Even though I find the ancient style stale and unsightly, we would want to keep the (GIT_DIR is set, GIT_WORK_TREE is not set anywhere) combination working for people who have work habits (read: old scripts) that rely on it. So we would discourage new tests from using ancient style, but at the same time, we would not want to remove _all_ existing ones.
Unless we are trying to break them without knowing, and declare that we deprecated it after the fact, which is not exactly the way we want to remove existing (mis)feature.
Same comment applies to the other patch that removes the test that uses update-index && update-ref combination to a lessor degree.
The [PATCH 2/3] is a genuine improvement, though.
Thanks.
Re: [PATCH 3/3] t5403: do not use access repos with GIT_DIR when worktree is involved
2011/10/13 Junio C Hamano <[email protected]>:
Quoted 6 lines
Quoted 4 lines · Nguyễn Thái Ngọc Duy
Setting
GIT_DIRalone means worktree is current directory for legacy reasons. Avoid using that, instead go to the worktree and execute commands there.
Quoted 8 lines
Quoted 4 lines
The troublesome command is "GIT_DIR=clone2/.git git add clone2/b". The real worktree is clone2, but that command tells git worktree is $(pwd). What does user expect to add then? Should the new entry in index be "b" or "clone2/b"?
There is no troublesomeness here, as the semantics has been clearly defined and (hopefully) stayed constant before the days when
GIT_WORK_TREEwas invented.
It's not wrong per se. The trouble comes from the people who reads the test. It's not clear the author wants to add "b" or "clone2/b".
Another thing, because "clone2" has .git inside, should "clone2" in this case be considered a submodule and "git add" refuse to add anything "clone2/*" but "clone2" itself?
Quoted 3 lines
Unless we are trying to break them without knowing, and declare that we deprecated it after the fact, which is not exactly the way we want to remove existing (mis)feature.
I had problems with my read_directory() rewrite but it's been some time since I touched the code. I don't remember what went wrong. Need to have another look.
Signature · 1 line
Duy
Am 10/12/2011 11:35, schrieb Nguyễn Thái Ngọc Duy:
t/t5403-post-checkout-hook.sh test_description='Test the post-checkout hook.' · line 16
Quoted 13 lines
test_expect_successsetup 't/t5403-post-checkout-hook.sh +2
-5echo 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 add a b && + git commit -m setup && git clone ./. clone1 && git clone ./. clone2 && GIT_DIR=clone2/.git git branch new2 &&
I don't think this change is necessary. It doesn't hurt to use plumbing commands here and there in the test suite to exercise them to a degree that they deserve.
-- Hannes
2011/10/13 Johannes Sixt <[email protected]>:
Quoted 15 lines
Am 10/12/2011 11:35, schrieb Nguyễn Thái Ngọc Duy:
Quoted 5 lines
test_expect_success setup '
echo Data for commit0. >a &&
echo Data for commit0. >b &&
- git update-index --add a &&
- git update-index --add b &&Quoted 8 lines
- tree0=$(git write-tree) &&
- commit0=$(echo setup | git commit-tree $tree0) &&
- git update-ref refs/heads/master $commit0 &&
+ git add a b &&
+ git commit -m setup &&
git clone ./. clone1 &&
git clone ./. clone2 && GIT_DIR=clone2/.git git branch new2 &&
Quoted 3 lines
I don't think this change is necessary. It doesn't hurt to use plumbing commands here and there in the test suite to exercise them to a degree that they deserve.
I'm fine either way, for the record.
Signature · 1 line
Duy