rebase/histedit -l: error out if no backups for the requested branch exist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/got/got.c b/got/got.c
index 28c535e..5d1639c 100644
--- a/got/got.c
+++ b/got/got.c
@@ -7923,6 +7923,7 @@ list_backup_refs(const char *backup_ref_prefix, const char *wanted_branch_name,
char *branch_name = NULL;
struct got_commit_object *old_commit = NULL;
struct got_reflist_object_id_map *refs_idmap = NULL;
+ int wanted_branch_found = 0;
TAILQ_INIT(&refs);
TAILQ_INIT(&backup_refs);
@@ -7978,6 +7979,7 @@ list_backup_refs(const char *backup_ref_prefix, const char *wanted_branch_name,
if (wanted_branch_name == NULL ||
strcmp(wanted_branch_name, branch_name) == 0) {
+ wanted_branch_found = 1;
err = print_backup_ref(branch_name, refname,
old_commit_id, old_commit, refs_idmap, repo);
if (err)
@@ -7991,6 +7993,11 @@ list_backup_refs(const char *backup_ref_prefix, const char *wanted_branch_name,
got_object_commit_close(old_commit);
old_commit = NULL;
}
+
+ if (wanted_branch_name && !wanted_branch_found) {
+ err = got_error_fmt(GOT_ERR_NOT_REF,
+ "%s/%s/", backup_ref_prefix, wanted_branch_name);
+ }
done:
if (refs_idmap)
got_reflist_object_id_map_free(refs_idmap);
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index f972bec..432e94f 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -172,6 +172,25 @@ EOF
ret="$?"
if [ "$ret" != "0" ]; then
diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ fi
+
+ # Asking for backups of a branch which has none should yield an error
+ (cd $testroot/repo && got rebase -l master \
+ > $testroot/stdout 2> $testroot/stderr)
+ echo -n > $testroot/stdout.expected
+ echo "got: refs/got/backup/rebase/master/: no such reference found" \
+ > $testroot/stderr.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ fi
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
fi
test_done "$testroot" "$ret"
}