fix behaviour of 'got rebase' with no commits to rebase; with semarie@
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/got/got.c b/got/got.c
index 486e9fe..24418f1 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4268,6 +4268,20 @@ cmd_rebase(int argc, char *argv[])
parent_ids = got_object_commit_get_parent_ids(commit);
pid = SIMPLEQ_FIRST(parent_ids);
+ if (pid == NULL) {
+ if (!continue_rebase) {
+ int did_something;
+ error = got_worktree_rebase_abort(worktree, fileindex,
+ repo, new_base_branch, update_progress,
+ &did_something);
+ if (error)
+ goto done;
+ printf("Rebase of %s aborted\n",
+ got_ref_get_name(branch));
+ }
+ error = got_error(GOT_ERR_EMPTY_REBASE);
+ goto done;
+ }
error = collect_commits(&commits, commit_id, pid->id,
yca_id, got_worktree_get_path_prefix(worktree),
GOT_ERR_REBASE_PATH, repo);
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index fb98c2f..0d64a54 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -714,6 +714,55 @@ function test_rebase_preserves_logmsg {
test_done "$testroot" "$ret"
}
+function test_rebase_no_commits_to_rebase {
+ local testroot=`test_init rebase_no_commits_to_rebase`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got branch newbranch)
+
+ echo "modified alpha on master" > $testroot/wt/alpha
+ (cd $testroot/wt && got commit -m 'test rebase_no_commits_to_rebase' \
+ > /dev/null)
+ (cd $testroot/wt && got update > /dev/null)
+
+ (cd $testroot/wt && got rebase newbranch > $testroot/stdout \
+ 2> $testroot/stderr)
+
+ echo "got: no commits to rebase" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "Rebase of refs/heads/newbranch aborted" \
+ > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ (cd $testroot/wt && got update > $testroot/stdout)
+ echo "Already up-to-date" > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_rebase_basic
run_test test_rebase_ancestry_check
run_test test_rebase_continue
@@ -722,3 +771,4 @@ run_test test_rebase_no_op_change
run_test test_rebase_in_progress
run_test test_rebase_path_prefix
run_test test_rebase_preserves_logmsg
+run_test test_rebase_no_commits_to_rebase