commit 54eb00d5beb979ca755db29889d236201e53cd52 from: Stefan Sperling date: Tue Oct 20 22:25:57 2020 UTC properly handle nonexistent remote repository names given to 'got fetch' found by jrick ok naddy commit - 2513f20abd32eca0e2f74e92abd73629b4360258 commit + 54eb00d5beb979ca755db29889d236201e53cd52 blob - 9ff54863f6b41daa7b9bf2b9cb46bf28b42ffe52 blob + 138291e3421f28ca4a7541d072a13b359720b717 --- got/got.c +++ got/got.c @@ -2119,9 +2119,10 @@ cmd_fetch(int argc, char *argv[]) got_gotconfig_get_remotes(&nremotes, &remotes, worktree_conf); for (i = 0; i < nremotes; i++) { - remote = &remotes[i]; - if (strcmp(remote->name, remote_name) == 0) + if (strcmp(remotes[i].name, remote_name) == 0) { + remote = &remotes[i]; break; + } } } } @@ -2131,18 +2132,20 @@ cmd_fetch(int argc, char *argv[]) got_gotconfig_get_remotes(&nremotes, &remotes, repo_conf); for (i = 0; i < nremotes; i++) { - remote = &remotes[i]; - if (strcmp(remote->name, remote_name) == 0) + if (strcmp(remotes[i].name, remote_name) == 0) { + remote = &remotes[i]; break; + } } } } if (remote == NULL) { got_repo_get_gitconfig_remotes(&nremotes, &remotes, repo); for (i = 0; i < nremotes; i++) { - remote = &remotes[i]; - if (strcmp(remote->name, remote_name) == 0) + if (strcmp(remotes[i].name, remote_name) == 0) { + remote = &remotes[i]; break; + } } } if (remote == NULL) { blob - 059c1dc9b29d8efbb092fcd4eaf3bbccc36da1c3 blob + 3f5693ec2c5a3685f79649772017c3e4db3e9779 --- regress/cmdline/fetch.sh +++ regress/cmdline/fetch.sh @@ -978,6 +978,18 @@ remote "barbaz" { repository "$testroot/does-not-exist" } EOF + echo "got: nonexistent: remote repository not found" \ + > $testroot/stderr.expected + (cd $testroot/repo-clone && got fetch nonexistent \ + > $testroot/stdout 2> $testroot/stderr) + ret="$?" + if [ "$ret" == "0" ]; then + echo "got fetch command succeeded unexpectedly" >&2 + diff -u $testroot/stderr.expected $testroot/stderr + test_done "$testroot" "1" + return 1 + fi + (cd $testroot/repo-clone && got fetch -l foobar \ > $testroot/stdout) ret="$?"