{"thread":{"id":"33167","subject":"[PATCH 0/2] git subtree: properly handle remote refs","startedAt":"2013-03-13T16:17:30Z","lastAt":"2013-03-13T16:17:32Z","messageCount":3,"participants":["Jérémy Rosen"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"211224","messageId":"1363191452-28804-1-git-send-email-jeremy.rosen@openwide.fr","threadId":"33167","inReplyTo":null,"subject":"[PATCH 0/2] git subtree: properly handle remote refs","fromName":"Jérémy Rosen","fromEmail":"jeremy.rosen@openwide.fr","sentAt":"2013-03-13T16:17:30Z","receivedAt":"2013-03-13T16:17:30Z","isPatch":true,"sender":{"key":"jeremy.rosen@openwide.fr","avatar":null},"body":"One common use-case for git subtree is to use it only on taged commits from the remote project. however the current implementation of gi-subtree can not be used in that way. two orthogonal prevent this\n\nthe SHA used as the origin revision can be the SHA of a tag which isn't available locally. This works correctly at merge time but will fail at split time. The first patch uses the ^{} notation to make sure a correct commit SHA is used instead of the SHA given as a parameter\n\nthe checks for the correctness of the target ref to pull or add checks that the name matches a local ref (which is incorrect). The second patch use ls-remote to validate the ref name given against the ones in the remote repository\n\nJérémy Rosen (2):\n  git-subtree: make sure the SHA saved as ancestor is a commit\n  git-subtree: use ls-remote to check the refspec passed to pull and\n    add\n\n contrib/subtree/git-subtree.sh |   15 ++++++---------\n 1 file changed, 6 insertions(+), 9 deletions(-)\n\n-- \n1.7.10.4\n"},{"id":"211225","messageId":"1363191452-28804-2-git-send-email-jeremy.rosen@openwide.fr","threadId":"33167","inReplyTo":"1363191452-28804-1-git-send-email-jeremy.rosen@openwide.fr","subject":"[PATCH 1/2] git-subtree: make sure the SHA saved as ancestor is a commit","fromName":"Jérémy Rosen","fromEmail":"jeremy.rosen@openwide.fr","sentAt":"2013-03-13T16:17:31Z","receivedAt":"2013-03-13T16:17:31Z","isPatch":true,"sender":{"key":"jeremy.rosen@openwide.fr","avatar":null},"body":"When adding or merging the first parameter might not be a commit, it can also be a tag SHA.\nThis needs to be fixed by using the underlying commit or the ancestor finding code will croak at split time\n\n\nSigned-off-by: Jérémy Rosen <jeremy.rosen@openwide.fr>\n---\n contrib/subtree/git-subtree.sh |    4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 8a23f58..8b9d114 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -531,7 +531,7 @@ cmd_add_repository()\n \n cmd_add_commit()\n {\n-\trevs=$(git rev-parse $default --revs-only \"$@\") || exit $?\n+\trevs=$(git rev-parse $default --revs-only \"$1^{commit}\") || exit $?\n \tset -- $revs\n \trev=\"$1\"\n \t\n@@ -655,7 +655,7 @@ cmd_split()\n \n cmd_merge()\n {\n-\trevs=$(git rev-parse $default --revs-only \"$@\") || exit $?\n+\trevs=$(git rev-parse $default --revs-only \"$1^{commit}\") || exit $?\n \tensure_clean\n \t\n \tset -- $revs\n-- \n1.7.10.4\n"},{"id":"211226","messageId":"1363191452-28804-3-git-send-email-jeremy.rosen@openwide.fr","threadId":"33167","inReplyTo":"1363191452-28804-1-git-send-email-jeremy.rosen@openwide.fr","subject":"[PATCH 2/2] git-subtree: use ls-remote to check the refspec passed to pull and add","fromName":"Jérémy Rosen","fromEmail":"jeremy.rosen@openwide.fr","sentAt":"2013-03-13T16:17:32Z","receivedAt":"2013-03-13T16:17:32Z","isPatch":true,"sender":{"key":"jeremy.rosen@openwide.fr","avatar":null},"body":"ls-remote is the correct way to check that a parameter is a valid fetchable target\n\n\nSigned-off-by: Jérémy Rosen <jeremy.rosen@openwide.fr>\n---\n contrib/subtree/git-subtree.sh |   11 ++++-------\n 1 file changed, 4 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 8b9d114..61d4eab 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -503,13 +503,8 @@ cmd_add()\n \n \t    \"cmd_add_commit\" \"$@\"\n \telif [ $# -eq 2 ]; then\n-\t    # Technically we could accept a refspec here but we're\n-\t    # just going to turn around and add FETCH_HEAD under the\n-\t    # specified directory.  Allowing a refspec might be\n-\t    # misleading because we won't do anything with any other\n-\t    # branches fetched via the refspec.\n-\t    git rev-parse -q --verify \"$2^{commit}\" >/dev/null ||\n-\t    die \"'$2' does not refer to a commit\"\n+\t\tgit ls-remote --exit-code \"$1\" \"$2\" ||\n+\t\tdie \"'$2' is not a correct reference on '$1'\"\n \n \t    \"cmd_add_repository\" \"$@\"\n \telse\n@@ -700,6 +695,8 @@ cmd_merge()\n cmd_pull()\n {\n \tensure_clean\n+\tgit ls-remote --exit-code \"$1\" \"$2\" ||\n+\t\tdie \"'$2' is not a correct reference on '$1'\"\n \tgit fetch \"$@\" || exit $?\n \trevs=FETCH_HEAD\n \tset -- $revs\n-- \n1.7.10.4\n"}]}