From: Mark Jamsek Subject: Re: special case 'got fetch -b ' + regress To: Game of Trees Date: Mon, 13 Feb 2023 16:51:48 +1100 On 23-02-13 02:23AM, Mark Jamsek wrote: > As a related change, I'll follow up (tomorrow) with a diff that improves > the output when requesting a branch with 'got fetch -b' that does not > exist. Currently, we report: > > got-fetch-pack: could not find any branches to fetch > got: could not find any branches to fetch I remembered that stsp already had a diff to do just this (see: "improve got fetch error reporting"), so I've rebased his with a slight tweak (i.e., don't print the "could not find any branches to fetch" string twice) on top of the diff sent in the first message of this thread, and amended regress for the output change. As such, like stsp described in the abovementioned thread, when 'got fetch -b branch' fails, the report changes from: got-fetch-pack: could not find any branches to fetch got: could not find any branches to fetch to: got-fetch-pack: branch "foo" not found on server got: could not find any branches to fetch The following diff applies on top of the diff in the previous mail: diffstat /home/mark/src/got M libexec/got-fetch-pack/got-fetch-pack.c | 19+ 0- M regress/cmdline/fetch.sh | 2+ 2- 2 files changed, 21 insertions(+), 2 deletions(-) diff /home/mark/src/got commit - ffefb1bf10d7cef2f1c5f3e567b6e4cfe95cbc22 path + /home/mark/src/got blob - c8d35d7046be5e229cbdc28ec23f311320cfef70 file + libexec/got-fetch-pack/got-fetch-pack.c --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -513,6 +513,25 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, /* Abort if we haven't found anything to fetch. */ if (nref == 0) { + struct got_pathlist_entry *pe; + static char msg[PATH_MAX + 33]; + + pe = TAILQ_FIRST(wanted_branches); + if (pe) { + snprintf(msg, sizeof(msg), + "branch \"%s\" not found on server", pe->path); + err = got_error_msg(GOT_ERR_FETCH_NO_BRANCH, msg); + goto done; + } + + pe = TAILQ_FIRST(wanted_refs); + if (pe) { + snprintf(msg, sizeof(msg), + "reference \"%s\" not found on server", pe->path); + err = got_error_msg(GOT_ERR_FETCH_NO_BRANCH, msg); + goto done; + } + err = got_error(GOT_ERR_FETCH_NO_BRANCH); goto done; } blob - 32900e895fc896beef177d3ad156f591d1f1ffb8 file + regress/cmdline/fetch.sh --- regress/cmdline/fetch.sh +++ regress/cmdline/fetch.sh @@ -1568,7 +1568,7 @@ test_fetch_honor_wt_conf_bflag() { echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \ > $testroot/stdout.expected - echo "got-fetch-pack: could not find any branches to fetch" \ + echo "got-fetch-pack: branch \"foo\" not found on server" \ > $testroot/stderr.expected echo "got: could not find any branches to fetch" \ >> $testroot/stderr.expected @@ -1797,7 +1797,7 @@ test_fetch_honor_wt_conf_bflag() { echo "Connecting to \"origin\" ssh://127.0.0.1$testroot/repo" \ > $testroot/stdout.expected - echo "got-fetch-pack: could not find any branches to fetch" \ + echo "got-fetch-pack: branch \"bar\" not found on server" \ > $testroot/stderr.expected echo "got: could not find any branches to fetch" \ >> $testroot/stderr.expected -- Mark Jamsek GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68