Commit Diff


commit - cdd126b14a2b1b69ccc452b9ebfad6fc0687351f0b32bac8bd259ae4d5338600
commit + 9edd83064989e03ca1828e9ba7be70381f2e937a3dfa764b2cb29a86173af122
blob - 1b01b311404835b478c875e9dc8767f4f8d8622bfcfaee77c7b5c4bcc1f6f80f
blob + d547cebbf73093f2b7dd97e6c65110ec0db8c98b473808cb1b5ab7c3fed2c01e
--- libexec/got-fetch-pack/got-fetch-pack.c	
+++ libexec/got-fetch-pack/got-fetch-pack.c	
@@ -458,7 +458,11 @@ fetch_pack(int fd, int packfd, int expected_algo,
 				}
 			}
 			if (expected_algo != -1 && algo != expected_algo) {
-				err = got_error(GOT_ERR_OBJECT_FORMAT);
+				err = got_error_fmt(GOT_ERR_OBJECT_FORMAT,
+				    "the local repository uses %s hashes "
+				    "and the remote repository uses %s hashes",
+				    got_hash_algo_name(expected_algo),
+				    got_hash_algo_name(algo));
 				goto done;
 			}
 
blob - f709a7ff9e1781cf2a5d9207cc7b06cfa02082c23881eec4068e3d4847063e8b
blob + 75d8a48a57fc8875095310bd726033ba562c7e843817ab6a8bf7b6a5e39d7e25
--- regress/gotd/repo_read.sh	
+++ regress/gotd/repo_read.sh	
@@ -172,7 +172,60 @@ test_send_to_read_only_repo() {
 	test_done "$testroot" "$ret"
 }
 
+test_fetch_incompatible_hash_algo() {
+	local testroot=`test_init fetch_incompatible_hash_algo 1`
+
+	got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got clone failed unexpectedly" >&2
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	if [ "$GOT_TEST_ALGO" = "sha256" ]; then
+		other_hash=sha1
+	else
+		other_hash=sha256
+	fi
+
+	got init -A $other_hash $testroot/otherhash.git
+
+	cp $testroot/repo-clone/got.conf $testroot/otherhash.git
+
+	got fetch -q -r $testroot/otherhash.git \
+		> $testroot/stdout 2> $testroot/stderr
+	
+	echo -n "" > $testroot/stdout.expected
+
+	cmp -s $testroot/stdout.expected $testroot/stdout
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	echo -n "got-fetch-pack: " > $testroot/stderr.expected
+	echo -n "the local repository uses $other_hash hashes " \
+		>> $testroot/stderr.expected
+	echo -n "and the remote repository uses ${GOT_TEST_ALGO} hashes: " \
+		>> $testroot/stderr.expected
+	echo "object format not supported" >> $testroot/stderr.expected
+
+	grep '^got-fetch-pack' $testroot/stderr > $testroot/stderr.filtered
+
+	cmp -s $testroot/stderr.expected $testroot/stderr.filtered
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stderr.expected $testroot/stderr
+	fi
+
+	test_done "$testroot" "$ret"
+}
+
 test_parseargs "$@"
 run_test test_clone_basic
 run_test test_clone_basic_git
 run_test test_send_to_read_only_repo
+run_test test_fetch_incompatible_hash_algo