From edae5f0c20b7e71a717b59873ddb8eeddfa49b86 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 23 Apr 2008 09:47:17 -0700 Subject: write-tree: properly detect failure to write tree objects Tomasz Fortuna reported that "git commit" does not error out properly when it cannot write tree objects out. "git write-tree" shares the same issue, as the failure to notice the error is deep in the logic to write tree objects out recursively. Signed-off-by: Junio C Hamano --- t/t0004-unwritable.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 t/t0004-unwritable.sh (limited to 't') diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh new file mode 100755 index 0000000000..9255c63c08 --- /dev/null +++ b/t/t0004-unwritable.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +test_description='detect unwritable repository and fail correctly' + +. ./test-lib.sh + +test_expect_success setup ' + + >file && + git add file && + git commit -m initial && + echo >file && + git add file + +' + +test_expect_success 'write-tree should notice unwritable repository' ' + + ( + chmod a-w .git/objects + test_must_fail git write-tree + ) + status=$? + chmod 775 .git/objects + (exit $status) + +' + +test_expect_success 'commit should notice unwritable repository' ' + + ( + chmod a-w .git/objects + test_must_fail git commit -m second + ) + status=$? + chmod 775 .git/objects + (exit $status) + +' + +test_expect_success 'update-index should notice unwritable repository' ' + + ( + echo a >file && + chmod a-w .git/objects + test_must_fail git update-index file + ) + status=$? + chmod 775 .git/objects + (exit $status) + +' + +test_expect_success 'add should notice unwritable repository' ' + + ( + echo b >file && + chmod a-w .git/objects + test_must_fail git add file + ) + status=$? + chmod 775 .git/objects + (exit $status) + +' + +test_done -- cgit v1.2.1 From 3ef6a1fe95b0a5aaca21a86651850ef5d62327fa Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 23 Apr 2008 05:21:45 -0400 Subject: t5516: remove ambiguity test (1) This test tried to push into a remote with ambiguous refs in remotes/$x/master and remotes/$y/master. However, the remote never actually tells us about the refs/remotes hierarchy, so we don't even see this ambiguity. The test happened to pass because we were simply looking for failure, and the test fails for another reason: the dst refspec does not exist and does not begin with refs/, making it invalid. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t5516-fetch-push.sh | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 't') diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 9d2dc33cbd..352e83bdc6 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -178,19 +178,7 @@ test_expect_success 'push with weak ambiguity (2)' ' ' -test_expect_success 'push with ambiguity (1)' ' - - mk_test remotes/origin/master remotes/frotz/master && - if git push testrepo master:master - then - echo "Oops, should have failed" - false - else - check_push_result $the_first_commit remotes/origin/master remotes/frotz/master - fi -' - -test_expect_success 'push with ambiguity (2)' ' +test_expect_success 'push with ambiguity' ' mk_test heads/frotz tags/frotz && if git push testrepo master:frotz -- cgit v1.2.1 From f8aae120345f511e59bb008e8de2a8f6e65cf377 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 23 Apr 2008 05:16:06 -0400 Subject: push: allow unqualified dest refspecs to DWIM Previously, a push like: git push remote src:dst would go through the following steps: 1. check for an unambiguous 'dst' on the remote; if it exists, then push to that ref 2. otherwise, check if 'dst' begins with 'refs/'; if it does, create a new ref 3. otherwise, complain because we don't know where in the refs hierarchy to put 'dst' However, in some cases, we can guess about the ref type of 'dst' based on the ref type of 'src'. Specifically, before complaining we now check: 2.5. if 'src' resolves to a ref starting with refs/heads or refs/tags, then prepend that to 'dst' So now this creates a new branch on the remote, whereas it previously failed with an error message: git push master:newbranch Note that, by design, we limit this DWIM behavior only to source refs which resolve exactly (including symrefs which resolve to existing refs). We still complain on a partial destination refspec if the source is a raw sha1, or a ref expression such as 'master~10'. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t5516-fetch-push.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 't') diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index f93a100f87..0a757d5b9f 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -273,6 +273,37 @@ test_expect_success 'push with colon-less refspec (4)' ' ' +test_expect_success 'push head with non-existant, incomplete dest' ' + + mk_test && + git push testrepo master:branch && + check_push_result $the_commit heads/branch + +' + +test_expect_success 'push tag with non-existant, incomplete dest' ' + + mk_test && + git tag -f v1.0 && + git push testrepo v1.0:tag && + check_push_result $the_commit tags/tag + +' + +test_expect_success 'push sha1 with non-existant, incomplete dest' ' + + mk_test && + test_must_fail git push testrepo `git rev-parse master`:foo + +' + +test_expect_success 'push ref expression with non-existant, incomplete dest' ' + + mk_test && + test_must_fail git push testrepo master^:branch + +' + test_expect_success 'push with HEAD' ' mk_test heads/master && @@ -311,6 +342,15 @@ test_expect_success 'push with +HEAD' ' ' +test_expect_success 'push HEAD with non-existant, incomplete dest' ' + + mk_test && + git checkout master && + git push testrepo HEAD:branch && + check_push_result $the_commit heads/branch + +' + test_expect_success 'push with config remote.*.push = HEAD' ' mk_test heads/local && -- cgit v1.2.1 From 1ce89cc4bb18b0e66f7073562d6634f6a9841335 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 22 Apr 2008 07:11:13 -0400 Subject: remote: create fetch config lines with '+' Since git-remote always uses remote tracking branches, it should be safe to always force updates of those branches. I.e., we should generate fetch = +refs/heads/*:refs/remotes/$remote/* instead of fetch = refs/heads/*:refs/remotes/$remote/* This was the behavior of the perl version, which seems to have been lost in the C rewrite. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t5505-remote.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't') diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index af2d077792..48ff2d424d 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -77,6 +77,16 @@ test_expect_success 'add another remote' ' ) ' +test_expect_success 'remote forces tracking branches' ' +( + cd test && + case `git config remote.second.fetch` in + +*) true ;; + *) false ;; + esac +) +' + test_expect_success 'remove remote' ' ( cd test && -- cgit v1.2.1