commit b624328edd13c021ae254c221e3ebbfebb49ff6a from: James Cook date: Thu Jan 25 19:00:07 2024 UTC allow remotes without urls in git config Also, add tests. This change lets got and related tools work when the git config file has "remote" sections without urls, like this one in one of my git-annex git repositories: [remote "h0-rsync"] annex-rsyncurl = (some url) annex-uuid = (some uuid) skipFetchAll = true Running tog and many got commands there would previously result in: $ tog got-read-gitconfig: gitconfig syntax error tog: gitconfig syntax error The change to got-read-gitconfig.c is by stsp@, with ok from op@ (and now me). Tests ok stsp@. commit - f25a765e436b4da9fa7ea68c73e6f65a8f0d968e commit + b624328edd13c021ae254c221e3ebbfebb49ff6a blob - 99f2a5a5d4fdc582151efa06eb679bf4bfd09a69 blob + 4c5615e9a61fc968bb76b520dd500a60adaceb08 --- libexec/got-read-gitconfig/got-read-gitconfig.c +++ libexec/got-read-gitconfig/got-read-gitconfig.c @@ -195,6 +195,17 @@ get_boolean_val(char *val) strcmp(val, "1") == 0); } +static int +skip_node(struct got_gitconfig *gitconfig, struct got_gitconfig_list_node *node) +{ + /* + * Skip config nodes which do not describe remotes, and remotes + * which do not have a fetch URL defined (as used by git-annex). + */ + return (strncasecmp("remote \"", node->field, 8) != 0 || + got_gitconfig_get_str(gitconfig, node->field, "url") == NULL); +} + static const struct got_error * gitconfig_remotes_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig) { @@ -212,7 +223,7 @@ gitconfig_remotes_request(struct imsgbuf *ibuf, struct return err; TAILQ_FOREACH(node, §ions->fields, link) { - if (strncasecmp("remote \"", node->field, 8) != 0) + if (skip_node(gitconfig, node)) continue; nremotes++; } @@ -232,7 +243,7 @@ gitconfig_remotes_request(struct imsgbuf *ibuf, struct TAILQ_FOREACH(node, §ions->fields, link) { char *name, *end, *mirror; - if (strncasecmp("remote \"", node->field, 8) != 0) + if (skip_node(gitconfig, node)) continue; name = strdup(node->field + 8); @@ -247,20 +258,11 @@ 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; - } remotes[i].send_url = got_gitconfig_get_str(gitconfig, node->field, "pushurl"); if (remotes[i].send_url == NULL) - remotes[i].send_url = got_gitconfig_get_str(gitconfig, - node->field, "url"); - if (remotes[i].send_url == NULL) { - err = got_error(GOT_ERR_GITCONFIG_SYNTAX); - goto done; - } + remotes[i].send_url = remotes[i].fetch_url; remotes[i].mirror_references = 0; mirror = got_gitconfig_get_str(gitconfig, node->field, blob - bc9c071363d678f9caf6ad6317ddab429ffee389 blob + 609c219041bc3e37576915d5ae9e8f2cc180f7d7 --- regress/cmdline/fetch.sh +++ regress/cmdline/fetch.sh @@ -1372,7 +1372,50 @@ EOF echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected got ref -l -r $testroot/repo-clone > $testroot/stdout + + 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_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 <&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 @@ -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 <&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