commit - 2cbf1eb79a9a0aed8ad3417f74ec940343cee306
commit + 917cc2e31b6dba9d6598270b07c942a1c41ffcfe
blob - e001ff0ac88d80c90be055f13b7a2a79e386ede5
blob + 7afbff165a8d83cc740034cde9d4b97f2afeb3b4
--- got/got.c
+++ got/got.c
if (got_object_id_cmp(base_commit_id, yca_id) == 0) {
struct got_pathlist_head paths;
- printf("%s is already based on %s\n",
- got_ref_get_name(branch),
- got_worktree_get_head_ref_name(worktree));
+ const char *branch_name = got_ref_get_name(branch);
+ const char *base =
+ got_worktree_get_head_ref_name(worktree);
+
+ if (strcmp(branch_name, base) == 0) {
+ error = got_error_fmt(GOT_ERR_WRONG_BRANCH,
+ "cannot rebase %s onto itself",
+ branch_name);
+ goto done;
+ } else {
+ printf("%s is already based on %s\n",
+ branch_name, base);
+ }
error = switch_head_ref(branch, branch_head_commit_id,
worktree, repo);
if (error)
blob - 591ee66b8e3d659624ea402adc5cac155bfd6e21
blob + 43420d51963fb8796ed7148130020e3b879a4c8a
--- include/got_error.h
+++ include/got_error.h
#define GOT_ERR_BRANCH_EXISTS 83
#define GOT_ERR_MODIFIED 84
#define GOT_ERR_NOT_REBASING 85
-/* 86 is currently unused */
+#define GOT_ERR_WRONG_BRANCH 86
#define GOT_ERR_REBASE_COMMITID 87
#define GOT_ERR_REBASING 88
#define GOT_ERR_REBASE_PATH 89
blob - 8c70089b5c77c029b00e5f88e34d44bb64f6e5e2
blob + 27669f7e2444797982b2179fb2951d23802a30d0
--- lib/error.c
+++ lib/error.c
"changes must be committed or reverted first" },
{ GOT_ERR_NOT_REBASING, "rebase operation not in progress" },
{ GOT_ERR_REBASE_COMMITID,"rebase commit ID mismatch" },
+ { GOT_ERR_WRONG_BRANCH, "update -b required" },
{ GOT_ERR_REBASING, "a rebase operation is in progress in this "
"work tree and must be continued or aborted first" },
{ GOT_ERR_REBASE_PATH, "cannot rebase branch which contains "
blob - fae088133932111b4944a156b5ea1ac14d52df37
blob + fdc97d042d96cc880bf32dab15045285d6a80e27
--- regress/cmdline/rebase.sh
+++ regress/cmdline/rebase.sh
return 1
fi
+ (cd $testroot/wt && got rebase master > $testroot/stdout \
+ 2> $testroot/stderr)
+ echo -n "got: cannot rebase refs/heads/master onto itself: " \
+ > $testroot/stderr.expected
+ echo "update -b required" >> $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
(cd $testroot/wt && got rebase newbranch > $testroot/stdout)
git -C $testroot/repo checkout -q newbranch