contrib/subtree: ensure only one rev is provided

While looking at the inline help for git-subtree.sh, I noticed that

	git subtree split --prefix=<prefix> <commit...>

was given as an option. However, it only really makes sense to provide
one revision because of the way the commits are forwarded to rev-parse
so change "<commit...>" to "<commit>" to reflect this. In addition,
check the arguments to ensure that only one rev is provided for all
subcommands that accept a commit.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Acked-by: Avery Pennarun <apenwarr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Denton Liu 2019-03-11 02:47:17 -07:00 committed by Junio C Hamano
parent e902e9bcae
commit 77128ed90e
1 changed files with 12 additions and 12 deletions

View File

@ -14,7 +14,7 @@ git subtree add --prefix=<prefix> <repository> <ref>
git subtree merge --prefix=<prefix> <commit> git subtree merge --prefix=<prefix> <commit>
git subtree pull --prefix=<prefix> <repository> <ref> git subtree pull --prefix=<prefix> <repository> <ref>
git subtree push --prefix=<prefix> <repository> <ref> git subtree push --prefix=<prefix> <repository> <ref>
git subtree split --prefix=<prefix> <commit...> git subtree split --prefix=<prefix> <commit>
-- --
h,help show the help h,help show the help
q quiet q quiet
@ -77,6 +77,12 @@ assert () {
fi fi
} }


ensure_single_rev () {
if test $# -ne 1
then
die "You must provide exactly one revision. Got: '$@'"
fi
}


while test $# -gt 0 while test $# -gt 0
do do
@ -185,6 +191,7 @@ if test "$command" != "pull" &&
then then
revs=$(git rev-parse $default --revs-only "$@") || exit $? revs=$(git rev-parse $default --revs-only "$@") || exit $?
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $? dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
ensure_single_rev $revs
if test -n "$dirs" if test -n "$dirs"
then then
die "Error: Use --prefix instead of bare filenames." die "Error: Use --prefix instead of bare filenames."
@ -716,9 +723,8 @@ cmd_add_repository () {
} }


cmd_add_commit () { cmd_add_commit () {
revs=$(git rev-parse $default --revs-only "$@") || exit $? rev=$(git rev-parse $default --revs-only "$@") || exit $?
set -- $revs ensure_single_rev $rev
rev="$1"


debug "Adding $dir as '$rev'..." debug "Adding $dir as '$rev'..."
git read-tree --prefix="$dir" $rev || exit $? git read-tree --prefix="$dir" $rev || exit $?
@ -817,16 +823,10 @@ cmd_split () {
} }


cmd_merge () { cmd_merge () {
revs=$(git rev-parse $default --revs-only "$@") || exit $? rev=$(git rev-parse $default --revs-only "$@") || exit $?
ensure_single_rev $rev
ensure_clean ensure_clean


set -- $revs
if test $# -ne 1
then
die "You must provide exactly one revision. Got: '$revs'"
fi
rev="$1"

if test -n "$squash" if test -n "$squash"
then then
first_split="$(find_latest_squash "$dir")" first_split="$(find_latest_squash "$dir")"