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>
Denton Liu committed
Mar 11, 2019 at 02:47 UTC
77128ed90e9a24182e6606548e627753d8f034e1
1 file changed
+12
-12
contrib/subtree/git-subtree.sh
+12
-12
@@ -14,7 +14,7 @@ git subtree add --prefix=<prefix> <repository> <ref>
14
git subtree merge --prefix=<prefix> <commit>
15
git subtree pull --prefix=<prefix> <repository> <ref>
16
git subtree push --prefix=<prefix> <repository> <ref>
17
-git subtree split --prefix=<prefix> <commit...>
17
+git subtree split --prefix=<prefix> <commit>
18
--
19
h,help show the help
20
q quiet
@@ -77,6 +77,12 @@ assert () {
77
fi
78
}
79
80
+ensure_single_rev () {
81
+ if test $# -ne 1
82
+ then
83
+ die "You must provide exactly one revision. Got: '$@'"
84
+ fi
85
+}
86
87
while test $# -gt 0
88
do
@@ -185,6 +191,7 @@ if test "$command" != "pull" &&
191
then
192
revs=$(git rev-parse $default --revs-only "$@") || exit $?
193
dirs=$(git rev-parse --no-revs --no-flags "$@") || exit $?
194
+ ensure_single_rev $revs
195
if test -n "$dirs"
196
then
197
die "Error: Use --prefix instead of bare filenames."
@@ -716,9 +723,8 @@ cmd_add_repository () {
723
}
724
725
cmd_add_commit () {
719
- revs=$(git rev-parse $default --revs-only "$@") || exit $?
720
- set -- $revs
721
- rev="$1"
726
+ rev=$(git rev-parse $default --revs-only "$@") || exit $?
727
+ ensure_single_rev $rev
728
729
debug "Adding $dir as '$rev'..."
730
git read-tree --prefix="$dir" $rev || exit $?
@@ -817,16 +823,10 @@ cmd_split () {
823
}
824
825
cmd_merge () {
820
- revs=$(git rev-parse $default --revs-only "$@") || exit $?
826
+ rev=$(git rev-parse $default --revs-only "$@") || exit $?
827
+ ensure_single_rev $rev
828
ensure_clean
829
823
- set -- $revs
824
- if test $# -ne 1
825
- then
826
- die "You must provide exactly one revision. Got: '$revs'"
827
- fi
828
- rev="$1"
829
-
830
if test -n "$squash"
831
then
832
first_split="$(find_latest_squash "$dir")"