{"thread":{"id":"33041","subject":"[PATCH v2] contrib/subtree: allow addition of remote branch with name not locally present","startedAt":"2013-02-28T21:41:51Z","lastAt":"2013-02-28T21:41:51Z","messageCount":1,"participants":["Paul Campbell"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"210441","messageId":"CALeLG_m3A_52z=+NDrpttmTavzw68hnuWJZk8XHcN-smsQJupg@mail.gmail.com","threadId":"33041","inReplyTo":null,"subject":"[PATCH v2] contrib/subtree: allow addition of remote branch with name not locally present","fromName":"Paul Campbell","fromEmail":"pcampbell@kemitix.net","sentAt":"2013-02-28T21:41:51Z","receivedAt":"2013-02-28T21:41:51Z","isPatch":true,"sender":{"key":"pcampbell@kemitix.net","avatar":"https://gravatar.com/avatar/57584e05501b694929004e43fcd7308f4ad64df2eb0474cd8c7e5f93662bb0f1?d=mp&s=160"},"body":"cmd_add() attempts to check for the validity of refspec for the repository\nit is about to add as a subtree. It tries to do so before contacting the\nrepository. If the refspec happens to exist locally (say 'master') then\nthe test passes and the repo is fetched. If the refspec doesn't exist\nlocally then the test fails and the remote repo is never contacted.\n\nRemoving the tests still works as the git fetch command fails with the\nperfectly accurate error:\n\n  fatal: Couldn't find remote ref <refspec>\n\nNew tests check to prevent pulling in multiple branches or creating a local\nbranch for the subtree.\n\nSigned-off-by: Paul Campbell <pcampbell@carnegiecollege.ac.uk>\n---\n\nI've rerolled this with alternate tests.\n\nIs there anything else that should be tested for?\n\n contrib/subtree/git-subtree.sh | 15 ++++++++-------\n 1 file changed, 8 insertions(+), 7 deletions(-)\n\ndiff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh\nindex 8a23f58..d04bd25 100755\n--- a/contrib/subtree/git-subtree.sh\n+++ b/contrib/subtree/git-subtree.sh\n@@ -503,13 +503,14 @@ 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    case \"$2\" in\n+\t\t*\\**) # Avoid pulling in multiple branches\n+\t\t\tdie \"'$2' contains a wildcard\"\n+\t\t\t;;\n+\t\t*\\:*) # Don't create a local branch for the subtree\n+\t\t\tdie \"'$2' contains a local branch name\"\n+\t\t\t;;\n+\t    esac\n\n \t    \"cmd_add_repository\" \"$@\"\n \telse\n-- \n1.8.2.rc1\n"}]}