From d9c8344b467bb97b8dca8d811c99d4735eca88f2 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Fri, 9 Nov 2007 00:41:39 +0100 Subject: stop t1400 hiding errors in tests The last rm in the test was lacking an "&&" before it, which caused the errors in the commands be silently hidden. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index ce045b2a57..a90824ba8a 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -205,7 +205,7 @@ test_expect_success \ echo $h_TEST >.git/MERGE_HEAD && GIT_AUTHOR_DATE="2005-05-26 23:45" \ GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M && - h_MERGED=$(git rev-parse --verify HEAD) + h_MERGED=$(git rev-parse --verify HEAD) && rm -f M' cat >expect < Date: Tue, 15 Jan 2008 15:50:17 -0800 Subject: Be more careful about updating refs This makes write_ref_sha1() more careful: it actually checks the SHA1 of the ref it is updating, and refuses to update a ref with an object that it cannot find. Perhaps more importantly, it also refuses to update a branch head with a non-commit object. I don't quite know *how* the stable series maintainers were able to corrupt their repository to have a HEAD that pointed to a tag rather than a commit object, but they did. Which results in a totally broken repository that cannot be cloned or committed on. So make it harder for people to shoot themselves in the foot like that. The test t1400-update-ref.sh is fixed at the same time, as it assumed that the commands involved in the particular test would not care about corrupted repositories whose refs point at nonexistant bogus objects. That assumption does not hold true anymore. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index a90824ba8a..71ab2dd0ee 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -7,12 +7,19 @@ test_description='Test git update-ref and basic ref logging' . ./test-lib.sh Z=0000000000000000000000000000000000000000 -A=1111111111111111111111111111111111111111 -B=2222222222222222222222222222222222222222 -C=3333333333333333333333333333333333333333 -D=4444444444444444444444444444444444444444 -E=5555555555555555555555555555555555555555 -F=6666666666666666666666666666666666666666 + +test_expect_success setup ' + + for name in A B C D E F + do + test_tick && + T=$(git write-tree) && + sha1=$(echo $name | git commit-tree $T) && + eval $name=$sha1 + done + +' + m=refs/heads/master n_dir=refs/heads/gu n=$n_dir/fixes -- cgit v1.2.3 From 41ac414ea2bef81af94474cbef25a38868b4788e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 1 Feb 2008 01:50:53 -0800 Subject: Sane use of test_expect_failure Originally, test_expect_failure was designed to be the opposite of test_expect_success, but this was a bad decision. Most tests run a series of commands that leads to the single command that needs to be tested, like this: test_expect_{success,failure} 'test title' ' setup1 && setup2 && setup3 && what is to be tested ' And expecting a failure exit from the whole sequence misses the point of writing tests. Your setup$N that are supposed to succeed may have failed without even reaching what you are trying to test. The only valid use of test_expect_failure is to check a trivial single command that is expected to fail, which is a minority in tests of Porcelain-ish commands. This large-ish patch rewrites all uses of test_expect_failure to use test_expect_success and rewrites the condition of what is tested, like this: test_expect_success 'test title' ' setup1 && setup2 && setup3 && ! this command should fail ' test_expect_failure is redefined to serve as a reminder that that test *should* succeed but due to a known breakage in git it currently does not pass. So if git-foo command should create a file 'bar' but you discovered a bug that it doesn't, you can write a test like this: test_expect_failure 'git-foo should create bar' ' rm -f bar && git foo && test -f bar ' This construct acts similar to test_expect_success, but instead of reporting "ok/FAIL" like test_expect_success does, the outcome is reported as "FIXED/still broken". Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 71ab2dd0ee..78cd41245b 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -51,23 +51,23 @@ test_expect_success \ test $B"' = $(cat .git/'"$m"')' rm -f .git/$m -test_expect_failure \ - '(not) create HEAD with old sha1' \ - "git update-ref HEAD $A $B" -test_expect_failure \ - "(not) prior created .git/$m" \ - "test -f .git/$m" +test_expect_success '(not) create HEAD with old sha1' " + ! git update-ref HEAD $A $B +" +test_expect_success "(not) prior created .git/$m" " + ! test -f .git/$m +" rm -f .git/$m test_expect_success \ "create HEAD" \ "git update-ref HEAD $A" -test_expect_failure \ - '(not) change HEAD with wrong SHA1' \ - "git update-ref HEAD $B $Z" -test_expect_failure \ - "(not) changed .git/$m" \ - "test $B"' = $(cat .git/'"$m"')' +test_expect_success '(not) change HEAD with wrong SHA1' " + ! git update-ref HEAD $B $Z +" +test_expect_success "(not) changed .git/$m" " + ! test $B"' = $(cat .git/'"$m"') +' rm -f .git/$m : a repository with working tree always has reflog these days... -- cgit v1.2.3 From 40672a19042e618019cb4f7ba78ae25e554ce756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Hasselstr=C3=B6m?= Date: Sun, 25 May 2008 18:14:29 +0200 Subject: Add some tests for git update-ref -d MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Karl Hasselström Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 78cd41245b..b8b7ab4103 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -32,6 +32,14 @@ test_expect_success \ "create $m" \ "git update-ref $m $B $A && test $B"' = $(cat .git/'"$m"')' +test_expect_success "fail to delete $m with stale ref" ' + test_must_fail git update-ref -d $m $A && + test $B = "$(cat .git/$m)" +' +test_expect_success "delete $m" ' + git update-ref -d $m $B && + ! test -f .git/$m +' rm -f .git/$m test_expect_success \ @@ -49,6 +57,14 @@ test_expect_success \ "create $m (by HEAD)" \ "git update-ref HEAD $B $A && test $B"' = $(cat .git/'"$m"')' +test_expect_success "fail to delete $m (by HEAD) with stale ref" ' + test_must_fail git update-ref -d HEAD $A && + test $B = $(cat .git/$m) +' +test_expect_success "delete $m (by HEAD)" ' + git update-ref -d HEAD $B && + ! test -f .git/$m +' rm -f .git/$m test_expect_success '(not) create HEAD with old sha1' " -- cgit v1.2.3 From 3fe8dce6fc5b1d0bffba8fdb4e075fcd16cf5619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Hasselstr=C3=B6m?= Date: Tue, 3 Jun 2008 01:34:53 +0200 Subject: Make old sha1 optional with git update-ref -d MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Giving the old sha1 is already optional when changing a ref, and it's quite handy when running update-ref manually. So make it optional for deleting a ref too. Signed-off-by: Karl Hasselström Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index b8b7ab4103..f387d46f1a 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -42,6 +42,14 @@ test_expect_success "delete $m" ' ' rm -f .git/$m +test_expect_success "delete $m without oldvalue verification" " + git update-ref $m $A && + test $A = \$(cat .git/$m) && + git update-ref -d $m && + ! test -f .git/$m +" +rm -f .git/$m + test_expect_success \ "fail to create $n" \ "touch .git/$n_dir -- cgit v1.2.3 From d1a4489a56e2ceac8e7dc9eb277a9f36fec725c5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 8 Jul 2008 00:38:54 -0400 Subject: avoid null SHA1 in oldest reflog When the user specifies a ref by a reflog entry older than one we have (e.g., "HEAD@{20 years ago"}), we issue a warning and give them the "from" value of the oldest reflog entry. That is, we say "we don't know what happened before this entry, but before this we know we had some particular SHA1". However, the oldest reflog entry is often a creation event such as clone or branch creation. In this case, the entry claims that the ref went from "00000..." (the null sha1) to the new value, and the reflog lookup returns the null sha1. While this is technically correct (the entry tells us that the ref didn't exist at the specified time) it is not terribly useful to the end user. What they probably want instead is "the oldest useful sha1 that this ref ever had". This patch changes the behavior such that if the oldest ref would return the null sha1, it instead returns the first value the ref ever had. We never discovered this problem in the test scripts because we created "fake" reflogs that had only a specified segment of history. This patch updates the tests with a creation event at the beginning of history. Signed-off-by: Jeff King Acked-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index f387d46f1a..ca99d37616 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -155,7 +155,8 @@ rm -f .git/$m .git/logs/$m expect git update-ref $m $D cat >.git/logs/$m < 1117150320 -0500 +0000000000000000000000000000000000000000 $C $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500 +$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150350 -0500 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500 $F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500 $Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500 @@ -186,6 +187,12 @@ test_expect_success \ 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \ 'rm -f o e git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e && + test '"$C"' = $(cat o) && + test "" = "$(cat e)"' +test_expect_success \ + 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \ + 'rm -f o e + git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e && test '"$A"' = $(cat o) && test "" = "$(cat e)"' test_expect_success \ -- cgit v1.2.3 From d492b31cafe9aa5ce001b1d48815f4c0bb40d01a Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sat, 12 Jul 2008 17:47:52 +0200 Subject: t/: Use "test_must_fail git" instead of "! git" This patch changes every occurrence of "! git" -- with the meaning that a git call has to gracefully fail -- into "test_must_fail git". This is useful to - make sure the test does not fail because of a signal, e.g. SIGSEGV, and - advertise the use of "test_must_fail" for new tests. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index ca99d37616..b31e4b1ac6 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -76,7 +76,7 @@ test_expect_success "delete $m (by HEAD)" ' rm -f .git/$m test_expect_success '(not) create HEAD with old sha1' " - ! git update-ref HEAD $A $B + test_must_fail git update-ref HEAD $A $B " test_expect_success "(not) prior created .git/$m" " ! test -f .git/$m @@ -87,7 +87,7 @@ test_expect_success \ "create HEAD" \ "git update-ref HEAD $A" test_expect_success '(not) change HEAD with wrong SHA1' " - ! git update-ref HEAD $B $Z + test_must_fail git update-ref HEAD $B $Z " test_expect_success "(not) changed .git/$m" " ! test $B"' = $(cat .git/'"$m"') -- cgit v1.2.3 From 0cb0e143ffa7d66b7feea0a967b3ac9ae6cd62b0 Mon Sep 17 00:00:00 2001 From: Nanako Shiraishi Date: Wed, 3 Sep 2008 17:59:27 +0900 Subject: tests: use "git xyzzy" form (t0000 - t3599) Converts tests between t0050-t3903. Signed-off-by: Nanako Shiraishi Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index b31e4b1ac6..04c2b164bc 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -228,21 +228,21 @@ test_expect_success \ 'echo TEST >F && git add F && GIT_AUTHOR_DATE="2005-05-26 23:30" \ - GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a && + GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a && h_TEST=$(git rev-parse --verify HEAD) echo The other day this did not work. >M && echo And then Bob told me how to fix it. >>M && echo OTHER >F && GIT_AUTHOR_DATE="2005-05-26 23:41" \ - GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a && + GIT_COMMITTER_DATE="2005-05-26 23:41" git commit -F M -a && h_OTHER=$(git rev-parse --verify HEAD) && GIT_AUTHOR_DATE="2005-05-26 23:44" \ - GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend && + GIT_COMMITTER_DATE="2005-05-26 23:44" git commit --amend && h_FIXED=$(git rev-parse --verify HEAD) && echo Merged initial commit and a later commit. >M && echo $h_TEST >.git/MERGE_HEAD && GIT_AUTHOR_DATE="2005-05-26 23:45" \ - GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M && + GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M && h_MERGED=$(git rev-parse --verify HEAD) && rm -f M' @@ -253,7 +253,7 @@ $h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000 co $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 commit (merge): Merged initial commit and a later commit. EOF test_expect_success \ - 'git-commit logged updates' \ + 'git commit logged updates' \ "diff expect .git/logs/$m" unset h_TEST h_OTHER h_FIXED h_MERGED -- cgit v1.2.3 From 569740bdd0533ef5cf032edd6233710161a35725 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 26 Oct 2008 03:33:58 +0100 Subject: Fix git update-ref --no-deref -d. Till now --no-deref was just ignored when deleting refs, fix this. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 04c2b164bc..8139cd6cc9 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -75,6 +75,13 @@ test_expect_success "delete $m (by HEAD)" ' ' rm -f .git/$m +cp -f .git/HEAD .git/HEAD.orig +test_expect_success "delete symref without dereference" ' + git update-ref --no-deref -d HEAD && + ! test -f .git/HEAD +' +cp -f .git/HEAD.orig .git/HEAD + test_expect_success '(not) create HEAD with old sha1' " test_must_fail git update-ref HEAD $A $B " -- cgit v1.2.3 From 045a476f91a9a308c823a2709977163238baa3fd Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sat, 1 Nov 2008 00:25:44 +0100 Subject: update-ref --no-deref -d: handle the case when the pointed ref is packed In this case we did nothing in the past, but we should delete the reference in fact. The problem was that when the symref is not packed but the referenced ref is packed, then we assumed that the symref is packed as well, but symrefs are never packed. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 8139cd6cc9..bd589268fc 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -82,6 +82,17 @@ test_expect_success "delete symref without dereference" ' ' cp -f .git/HEAD.orig .git/HEAD +test_expect_success "delete symref without dereference when the referred ref is packed" ' + echo foo >foo.c && + git add foo.c && + git commit -m foo && + git pack-refs --all && + git update-ref --no-deref -d HEAD && + ! test -f .git/HEAD +' +cp -f .git/HEAD.orig .git/HEAD +git update-ref -d $m + test_expect_success '(not) create HEAD with old sha1' " test_must_fail git update-ref HEAD $A $B " -- cgit v1.2.3 From 188c3827c10f5a04588ef7af8b63a7b5dbcc38ed Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 16 Mar 2009 21:18:42 +0100 Subject: Tests: use test_cmp instead of diff where possible Several old tests were written before test_cmp was introduced, convert these to test_cmp. If were are at it, fix the order of the arguments where necessary to make expected come first, so the command shows how the test result deviates from the correct output. Signed-off-by: Miklos Vajna Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 't/t1400-update-ref.sh') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index bd589268fc..54ba3df95f 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -137,7 +137,7 @@ $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000 EOF test_expect_success \ "verifying $m's log" \ - "diff expect .git/logs/$m" + "test_cmp expect .git/logs/$m" rm -rf .git/$m .git/logs expect test_expect_success \ @@ -168,7 +168,7 @@ $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000 EOF test_expect_success \ "verifying $m's log" \ - 'diff expect .git/logs/$m' + 'test_cmp expect .git/logs/$m' rm -f .git/$m .git/logs/$m expect git update-ref $m $D @@ -272,7 +272,7 @@ $h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000 c EOF test_expect_success \ 'git commit logged updates' \ - "diff expect .git/logs/$m" + "test_cmp expect .git/logs/$m" unset h_TEST h_OTHER h_FIXED h_MERGED test_expect_success \ -- cgit v1.2.3