Skip to content

Commit 10a4958

Browse files
greenedgitster
authored andcommitted
contrib/subtree: better error handling for 'subtree add'
Check refspecs for validity before passing them on to other commands. This lets us generate more helpful error messages. Signed-off-by: David A. Greene <greened@obbligato.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a5b8e28 commit 10a4958

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

contrib/subtree/git-subtree.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,18 @@ cmd_add()
497497
ensure_clean
498498

499499
if [ $# -eq 1 ]; then
500-
"cmd_add_commit" "$@"
500+
git rev-parse -q --verify "$1^{commit}" >/dev/null ||
501+
die "'$1' does not refer to a commit"
502+
503+
"cmd_add_commit" "$@"
501504
elif [ $# -eq 2 ]; then
502-
"cmd_add_repository" "$@"
505+
git rev-parse -q --verify "$2^{commit}" >/dev/null ||
506+
die "'$2' does not refer to a commit"
507+
508+
"cmd_add_repository" "$@"
503509
else
504510
say "error: parameters were '$@'"
505-
die "Provide either a refspec or a repository and refspec."
511+
die "Provide either a commit or a repository and commit."
506512
fi
507513
}
508514

0 commit comments

Comments
 (0)