"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
James Cook <falsifian@falsifian.org>
Subject:
allow remotes without urls in git config; add tests
To:
gameoftrees@openbsd.org
Date:
Wed, 24 Jan 2024 18:16:02 +0000

Download raw body.

Thread
I have some git repos where .git/config has "remote" sections without 
urls, like this:

	[remote "h0-rsync"]
		annex-rsyncurl = (some url)
		annex-uuid = (some uuid)
		skipFetchAll = true

Running tog and many got commands there results in:

	$ tog
	got-read-gitconfig: gitconfig syntax error
	tog: gitconfig syntax error

The below diff makes got-read-gitconfig instead ignore these sections,
and adds test coverage for got fetch and got send commands that
read the git config.

I didn't touch the implementation in lib/read_gitconfig.c because
that seems to be only used by gotd, which I don't (yet) use and so
couldn't easily test. Is that duplicate implementation still needed?
I actually made my change there first and it took me a while to
realize it was the wrong place.

-- 
James


diff d0980f09b20ac878dcbc62fb940adf273a363f00 b9782d5c1f3fc2459e8cde0b58a1e128e43a2149
commit - d0980f09b20ac878dcbc62fb940adf273a363f00
commit + b9782d5c1f3fc2459e8cde0b58a1e128e43a2149
blob - 99f2a5a5d4fdc582151efa06eb679bf4bfd09a69
blob + d3e9edfcd3e76bd3faa07932fbdf44acbdebed5c
--- libexec/got-read-gitconfig/got-read-gitconfig.c
+++ libexec/got-read-gitconfig/got-read-gitconfig.c
@@ -248,8 +248,10 @@ gitconfig_remotes_request(struct imsgbuf *ibuf, struct
 		remotes[i].fetch_url = got_gitconfig_get_str(gitconfig,
 		    node->field, "url");
 		if (remotes[i].fetch_url == NULL) {
-			err = got_error(GOT_ERR_GITCONFIG_SYNTAX);
-			goto done;
+			free(remotes[i].name);
+			remotes[i].name = NULL;
+			--nremotes;
+			continue;
 		}
 
 		remotes[i].send_url = got_gitconfig_get_str(gitconfig,
blob - bc9c071363d678f9caf6ad6317ddab429ffee389
blob + 609c219041bc3e37576915d5ae9e8f2cc180f7d7
--- regress/cmdline/fetch.sh
+++ regress/cmdline/fetch.sh
@@ -1381,6 +1381,49 @@ EOF
 	test_done "$testroot" "$ret"
 }
 
+test_fetch_gitconfig_remote_repo() {
+	local testroot=`test_init fetch_gotconfig_remote_repo`
+	local testurl=ssh://127.0.0.1/$testroot
+	local commit_id=`git_show_head $testroot/repo`
+
+	make_single_file_repo $testroot/alternate-repo foo
+	local alt_commit_id=`git_show_head $testroot/alternate-repo`
+
+cat >> $testroot/repo/.git/config <<EOF
+[remote "hasnourl"]
+	unrelated = setting
+[remote "alt"]
+	url = $testurl/alternate-repo
+[remote "another"]
+	url = $testurl/some-other-repo
+EOF
+
+	# unset in a subshell to avoid affecting our environment
+	(unset GOT_IGNORE_GITCONFIG && cd $testroot/repo && got fetch -q alt)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got fetch command failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	got ref -l -r $testroot/repo > $testroot/stdout
+
+	cat > $testroot/stdout.expected <<-EOF
+		HEAD: refs/heads/master
+		refs/heads/master: $commit_id
+		refs/remotes/alt/HEAD: refs/remotes/alt/master
+		refs/remotes/alt/master: $alt_commit_id
+		EOF
+
+	cmp -s $testroot/stdout $testroot/stdout.expected
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
 test_fetch_delete_remote_refs() {
 	local testroot=`test_init fetch_delete_remote_refs`
 	local testurl=ssh://127.0.0.1/$testroot
@@ -1991,6 +2034,7 @@ run_test test_fetch_replace_symref
 run_test test_fetch_update_headref
 run_test test_fetch_headref_deleted_locally
 run_test test_fetch_gotconfig_remote_repo
+run_test test_fetch_gitconfig_remote_repo
 run_test test_fetch_delete_remote_refs
 run_test test_fetch_honor_wt_conf_bflag
 run_test test_fetch_from_out_of_date_remote
blob - 522e20e74edf14f00ee8062462c8e07e0fa3a63c
blob + b6f1c50eac455d297c5c32b125224755880ec879
--- regress/cmdline/send.sh
+++ regress/cmdline/send.sh
@@ -1556,6 +1556,52 @@ EOF
 	test_done "$testroot" "$ret"
 }
 
+test_send_gitconfig() {
+	local testroot=`test_init send_config`
+	local testurl=ssh://127.0.0.1/$testroot
+	local commit_id=`git_show_head $testroot/repo`
+
+	git init -q --bare $testroot/upstream-repo
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "git init failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+cat >> $testroot/repo/.git/config <<EOF
+[remote "hasnourl"]
+	unrelated = setting
+[remote "foo"]
+	url = $testurl/upstream-repo
+[remote "another"]
+	url = $testurl/some-other-repo
+EOF
+
+	# unset in a subshell to avoid affecting our environment
+	(unset GOT_IGNORE_GITCONFIG && got send -q -r $testroot/repo foo)
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "got send command failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	got ref -l -r $testroot/upstream-repo > $testroot/stdout
+
+	cat > $testroot/stdout.expected <<-EOF
+		HEAD: refs/heads/master
+		refs/heads/master: $commit_id
+		EOF
+
+	cmp -s $testroot/stdout $testroot/stdout.expected
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+	fi
+	test_done "$testroot" "$ret"
+}
+
 test_send_rejected() {
 	local testroot=`test_init send_rejected`
 	local testurl=ssh://127.0.0.1/$testroot
@@ -1633,4 +1679,5 @@ run_test test_send_all_branches
 run_test test_send_to_empty_repo
 run_test test_send_and_fetch_config
 run_test test_send_config
+run_test test_send_gitconfig
 run_test test_send_rejected