git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/7] contrib/subtree: Better Error Handling for add

From
David A. Greene <greened@obbligato.org>
Date
Jan 8, 2013, 12:09 UTC
Message-ID
<1357646997-28675-5-git-send-email-greened@obbligato.org>
In-Reply-To
<1357646997-28675-1-git-send-email-greened@obbligato.org>
From: "David A. Greene" <greened@obbligato.org>

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>
---
 contrib/subtree/git-subtree.sh |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index cac0680..d53eaee 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -508,12 +508,18 @@ cmd_add()
 	ensure_clean
 	
 	if [ $# -eq 1 ]; then
-		"cmd_add_commit" "$@"
+	    git rev-parse -q --verify "$1^{commit}" >/dev/null ||
+            die "'$1' does not refer to a commit"
+
+	    "cmd_add_commit" "$@"
 	elif [ $# -eq 2 ]; then
-		"cmd_add_repository" "$@"
+	    git rev-parse -q --verify "$2^{commit}" >/dev/null ||
+            die "'$2' does not refer to a commit"
+
+	    "cmd_add_repository" "$@"
 	else
 	    say "error: parameters were '$@'"
-	    die "Provide either a refspec or a repository and refspec."
+	    die "Provide either a commit or a repository and commit."
 	fi
 }
 
-- 
1.7.10.4
Previous: greened@obbligato.orgNext: Junio C Hamano
Message 17 of 22 in “Revised git-subtree Patches”
  1. David A. GreeneJan 8, 2013
  2. 1/7 Remove Test Number CommentsDavid A. Greene, Jan 8, 2013
  3. 2/7 contrib/subtree: Use %B for Split Subject/BodyDavid A. Greene, Jan 8, 2013
  4. Junio C HamanoJan 8, 2013
  5. greened@obbligato.orgJan 16, 2013
  6. 郑文辉 (Techlive Zheng)Jan 8, 2013
  7. Junio C HamanoJan 9, 2013
  8. greened@obbligato.orgJan 16, 2013
  9. Junio C HamanoJan 16, 2013
  10. greened@obbligato.orgJan 22, 2013
  11. 3/7 contrib/subtree: Add --unannotateDavid A. Greene, Jan 8, 2013
  12. Junio C HamanoJan 8, 2013
  13. greened@obbligato.orgJan 16, 2013
  14. greened@obbligato.orgJan 16, 2013
  15. Junio C HamanoJan 16, 2013
  16. greened@obbligato.orgJan 22, 2013
  17. 4/7 contrib/subtree: Better Error Handling for addDavid A. Greene, Jan 8, 2013
  18. Junio C HamanoJan 8, 2013
  19. greened@obbligato.orgJan 16, 2013
  20. 5/7 contrib/subtree: Fix SynopsisDavid A. Greene, Jan 8, 2013
  21. 6/7 contrib/subtree: Honor DESTDIRDavid A. Greene, Jan 8, 2013
  22. 7/7 contrib/subtree: Make the Manual Directory if NeededDavid A. Greene, Jan 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.