git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
To: git@vger.kernel.org
Cc: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Subject: [PATCH 2/5] rebase --root: print usage on too many args
Date: Tue, 26 Jun 2012 07:51:55 -0700	[thread overview]
Message-ID: <1340722318-24392-3-git-send-email-martin.von.zweigbergk@gmail.com> (raw)
In-Reply-To: <1340722318-24392-1-git-send-email-martin.von.zweigbergk@gmail.com>

Just like

  git rebase --onto newbase upstream branch error

displays the usage message, so should clearly

  git rebase --onto newbase --root branch error

, but it doesn't. Instead, it ignores both "branch" and "error" and
rebases the current HEAD. This is because we try to match the number
of remainging arguments "$#", which fails to match "1" argument and
matches the "*" that really should have been a "0".

Make sure we display usage information when too many arguments are
given. Also fail-fast in case of similar bugs in the future by
matching on exactly 0 arguments and failing on unknown numbers.
---
 git-rebase.sh          |    6 +++++-
 t/t3412-rebase-root.sh |    8 +++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/git-rebase.sh b/git-rebase.sh
index e616737..6df06c4 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -400,6 +400,7 @@ else
 	test -z "$onto" && die "You must specify --onto when using --root"
 	unset upstream_name
 	unset upstream
+	test $# -gt 1 && usage
 	upstream_arg=--root
 fi
 
@@ -450,7 +451,7 @@ case "$#" in
 		die "fatal: no such branch: $1"
 	fi
 	;;
-*)
+0)
 	# Do not need to switch branches, we are already on it.
 	if branch_name=`git symbolic-ref -q HEAD`
 	then
@@ -462,6 +463,9 @@ case "$#" in
 	fi
 	orig_head=$(git rev-parse --verify "${branch_name}^0") || exit
 	;;
+*)
+	die "BUG: unexpected number of arguments left to parse"
+	;;
 esac
 
 require_clean_work_tree "rebase" "Please commit or stash them."
diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh
index 086c91c..1e9d1a7 100755
--- a/t/t3412-rebase-root.sh
+++ b/t/t3412-rebase-root.sh
@@ -23,9 +23,15 @@ test_expect_success 'prepare repository' '
 '
 
 test_expect_success 'rebase --root expects --onto' '
+	git checkout -B fail other &&
 	test_must_fail git rebase --root
 '
 
+test_expect_success 'rebase --root fails with too many args' '
+	git checkout -B fail other &&
+	test_must_fail git rebase --onto master --root fail fail
+'
+
 test_expect_success 'setup pre-rebase hook' '
 	mkdir -p .git/hooks &&
 	cat >.git/hooks/pre-rebase <<EOF &&
@@ -42,7 +48,7 @@ cat > expect <<EOF
 EOF
 
 test_expect_success 'rebase --root --onto <newbase>' '
-	git checkout -b work &&
+	git checkout -b work other &&
 	git rebase --root --onto master &&
 	git log --pretty=tformat:"%s" > rebased &&
 	test_cmp expect rebased
-- 
1.7.9.3.327.g2980b

  parent reply	other threads:[~2012-06-26 14:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-26 14:51 [PATCH 0/5] rebase: calculate patches in upstream correctly Martin von Zweigbergk
2012-06-26 14:51 ` [PATCH 1/5] rebase: don't source git-sh-setup twice Martin von Zweigbergk
2012-06-26 14:51 ` Martin von Zweigbergk [this message]
2012-06-26 14:51 ` [PATCH 3/5] am --rebasing: get patch body from commit, not from mailbox Martin von Zweigbergk
2012-06-26 14:51 ` [PATCH 4/5] am: don't call mailinfo if $rebasing Martin von Zweigbergk
2012-06-26 14:51 ` [PATCH 5/5] rebase [-m]: calculate patches in upstream correctly Martin von Zweigbergk
2012-06-26 21:13   ` Junio C Hamano
2012-06-27 16:17     ` Martin von Zweigbergk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340722318-24392-3-git-send-email-martin.von.zweigbergk@gmail.com \
    --to=martin.von.zweigbergk@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).