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

[PATCH 2/2] git-subtree: use ls-remote to check the refspec passed to pull and add

From
JRJérémy Rosen <jeremy.rosen@openwide.fr>
Date
Mar 13, 2013, 16:17 UTC
Message-ID
<1363191452-28804-3-git-send-email-jeremy.rosen@openwide.fr>
In-Reply-To
<1363191452-28804-1-git-send-email-jeremy.rosen@openwide.fr>
ls-remote is the correct way to check that a parameter is a valid fetchable target
Signed-off-by: Jérémy Rosen <jeremy.rosen@openwide.fr>
---
 contrib/subtree/git-subtree.sh |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8b9d114..61d4eab 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -503,13 +503,8 @@ cmd_add()
 
 	    "cmd_add_commit" "$@"
 	elif [ $# -eq 2 ]; then
-	    # Technically we could accept a refspec here but we're
-	    # just going to turn around and add FETCH_HEAD under the
-	    # specified directory.  Allowing a refspec might be
-	    # misleading because we won't do anything with any other
-	    # branches fetched via the refspec.
-	    git rev-parse -q --verify "$2^{commit}" >/dev/null ||
-	    die "'$2' does not refer to a commit"
+		git ls-remote --exit-code "$1" "$2" ||
+		die "'$2' is not a correct reference on '$1'"
 
 	    "cmd_add_repository" "$@"
 	else
@@ -700,6 +695,8 @@ cmd_merge()
 cmd_pull()
 {
 	ensure_clean
+	git ls-remote --exit-code "$1" "$2" ||
+		die "'$2' is not a correct reference on '$1'"
 	git fetch "$@" || exit $?
 	revs=FETCH_HEAD
 	set -- $revs
-- 
1.7.10.4
Previous: Jérémy Rosen
Message 3 of 3 in “git subtree: properly handle remote refs”
  1. 0/2 git subtree: properly handle remote refsJérémy Rosen, Mar 13, 2013
  2. 1/2 git-subtree: make sure the SHA saved as ancestor is a commitJérémy Rosen, Mar 13, 2013
  3. 2/2 git-subtree: use ls-remote to check the refspec passed to pull and addJérémy Rosen, Mar 13, 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.