{"thread":{"id":"20483","subject":"git failing to create new branches, depending on the name","startedAt":"2009-08-08T15:32:55Z","lastAt":"2009-08-08T17:35:47Z","messageCount":4,"participants":["Artur Skawina","Thomas Rast","Daniel Barkalow"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"119990","messageId":"4A7D9AA7.1030709@gmail.com","threadId":"20483","inReplyTo":null,"subject":"git failing to create new branches, depending on the name","fromName":"Artur Skawina","fromEmail":"art.08.09@gmail.com","sentAt":"2009-08-08T15:32:55Z","receivedAt":"2009-08-08T15:32:55Z","isPatch":false,"sender":{"key":"art.08.09@gmail.com","avatar":null},"body":"One of my build scripts, which takes a 'work' git tree, clones it to\nmake a build tree, then creates an unique branch there and goes on\nto do the rest of the work, started mysteriously failing recently\n.\nTurns out git doesn't like the branch names that my script is\nchoosing and git-checkout fails with a misleading fatal error.\nI don't remember changing the script recently and it used to work\nfor months, something must have changed.\n\nThis is what i did while trying to find why the checkout is failing:\n\n+ git --version\ngit version 1.6.4\n+ rm -rf /tmp/build-tree\n+ git clone -l -s -n -o askern --reference /tmp/work-tree /tmp/work-tree /tmp/build-tree\nInitialized empty Git repository in /tmp/build-tree/.git/\n+ cd /tmp/build-tree\n+ git branch -a | grep g90bc1a6 \n+ git checkout -f -b branch-g90bc1a6 askern/release\nfatal: git checkout: branch branch-g90bc1a6 already exists\n# WTF?\n+ (\n+  cd /tmp/work-tree\n+  git branch -a | grep g90bc1a6\n+ )\n# nothing in parent repo either.\n+ git checkout -f branch-g90bc1a6 \nChecking out files: 100% (29109/29109), done.\nNote: moving to 'branch-g90bc1a6' which isn't a local branch\nIf you want to create a new branch from this checkout, you may do so\n(now or later) by using -b with the checkout command again. Example:\n  git checkout -b <new_branch_name>\nHEAD is now at 90bc1a6... Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus\n# so where is coming from?\n+ git branch -a | grep g90bc1a6\n+ git status\n# Not currently on any branch.\nnothing to commit (working directory clean)\n+  git show --pretty=short 90bc1a6 | cat\ncommit 90bc1a658a53f8832ee799685703977a450e5af9\nMerge: 6ce90c4 54822de\nAuthor: Linus Torvalds <torvalds@linux-foundation.org>\n\n    Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus\n# Aha\n\nSo what appears to be happening is that the script picks up the\n90bc1a6 suffix (it gets it from git-describe), uses it as part\nof the branch name and then git misinterprets it.\n(the actual names used by the script are much longer, i used\n\"branch-g90bc1a6\" only to figure what was going on)\n\nartur\n"},{"id":"119998","messageId":"200908081904.58186.trast@student.ethz.ch","threadId":"20483","inReplyTo":"4A7D9AA7.1030709@gmail.com","subject":"Re: git failing to create new branches, depending on the name","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-08-08T17:04:57Z","receivedAt":"2009-08-08T17:04:57Z","isPatch":false,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Artur Skawina wrote:\n> + git checkout -f -b branch-g90bc1a6 askern/release\n> fatal: git checkout: branch branch-g90bc1a6 already exists\n\nThis bisects to\n\ncommit 352eadc40024b141e1295693654ec20cc123844f\nAuthor: Daniel Barkalow <barkalow@iabervon.org>\nDate:   Sun Sep 21 14:36:06 2008 -0400\n\n    Check early that a new branch is new and valid\n\n    If you fail to update refs to change branches in checkout, your index\n    and working tree are left already updated. We don't have an easy way\n    to undo this, but at least we can check things that would make the\n    creation of a new branch fail. These checks were in the shell version,\n    and were lost in the C conversion.\n\n    The messages are from the shell version, and should probably be made nicer.\n\n    [jc: added test to t7201]\n\n    Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>\n    Signed-off-by: Junio C Hamano <gitster@pobox.com>\n\n\nNot sure this is a bug though.  If we allow branch names that are\nambiguous to rev-parse, what do they resolve to?  E.g., in the\npresence of only 'master', 'master-g01234567' is defined to be the\nsame as 01234567.  What is it if you also have a *branch* called\n'master-g01234567'?\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"120000","messageId":"4A7DB6E1.3000302@gmail.com","threadId":"20483","inReplyTo":"200908081904.58186.trast@student.ethz.ch","subject":"Re: git failing to create new branches, depending on the name","fromName":"Artur Skawina","fromEmail":"art.08.09@gmail.com","sentAt":"2009-08-08T17:33:21Z","receivedAt":"2009-08-08T17:33:21Z","isPatch":false,"sender":{"key":"art.08.09@gmail.com","avatar":null},"body":"Thomas Rast wrote:\n> Artur Skawina wrote:\n>> + git checkout -f -b branch-g90bc1a6 askern/release\n>> fatal: git checkout: branch branch-g90bc1a6 already exists\n> \n> This bisects to\n> \n> commit 352eadc40024b141e1295693654ec20cc123844f\n> Author: Daniel Barkalow <barkalow@iabervon.org>\n> Date:   Sun Sep 21 14:36:06 2008 -0400\n> \n>     Check early that a new branch is new and valid\n\n> Not sure this is a bug though.  If we allow branch names that are\n\nwell, it didn't say it didn't like the name, and sent me looking\nfor bugs in my scripts for quite a while, until i realized what's\ngoing on...\n\n> ambiguous to rev-parse, what do they resolve to?  E.g., in the\n> presence of only 'master', 'master-g01234567' is defined to be the\n> same as 01234567.  What is it if you also have a *branch* called\n> 'master-g01234567'?\n\nI'd expect the branch namespace to take precedence, unless branches\nending in -g01234567 are illegal, but that seems like an odd limitation.\n\nNote that currently this works:\n\n+ ( cd /tmp/build-tree/ && git checkout -f whatever/random-name-g90bc1a6 )\nHEAD is now at 90bc1a6... Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus\n\nwhich doesn't seem right either.\n\nartur\n"},{"id":"120001","messageId":"alpine.LNX.2.00.0908081312140.2147@iabervon.org","threadId":"20483","inReplyTo":"4A7D9AA7.1030709@gmail.com","subject":"Re: git failing to create new branches, depending on the name","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2009-08-08T17:35:47Z","receivedAt":"2009-08-08T17:35:47Z","isPatch":false,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"On Sat, 8 Aug 2009, Artur Skawina wrote:\n\n> One of my build scripts, which takes a 'work' git tree, clones it to\n> make a build tree, then creates an unique branch there and goes on\n> to do the rest of the work, started mysteriously failing recently\n> .\n> Turns out git doesn't like the branch names that my script is\n> choosing and git-checkout fails with a misleading fatal error.\n> I don't remember changing the script recently and it used to work\n> for months, something must have changed.\n> \n> This is what i did while trying to find why the checkout is failing:\n> \n> + git --version\n> git version 1.6.4\n> + rm -rf /tmp/build-tree\n> + git clone -l -s -n -o askern --reference /tmp/work-tree /tmp/work-tree /tmp/build-tree\n> Initialized empty Git repository in /tmp/build-tree/.git/\n> + cd /tmp/build-tree\n> + git branch -a | grep g90bc1a6 \n> + git checkout -f -b branch-g90bc1a6 askern/release\n> fatal: git checkout: branch branch-g90bc1a6 already exists\n> # WTF?\n\nPerhaps it shouldn't say \"branch branch-g90bc1a6\", but...\n\n> + (\n> +  cd /tmp/work-tree\n> +  git branch -a | grep g90bc1a6\n> + )\n> # nothing in parent repo either.\n> + git checkout -f branch-g90bc1a6 \n> Checking out files: 100% (29109/29109), done.\n\n\"branch-g90bc1a6\" does already exist, in the sense that you can already \ncheck it out. It's probably a bad idea, from the point of view of having \nyour repository make sense, to have a branch whose name is a valid name \nfor a different commit (or, in any case, a commit not specified by the \ncurrent value of the branch).\n\nThe check was added (restored, actually; it had been lost in the \nconversion to C) in order to prevent people from accidentally making local\nbranches named things like \"origin/master\" when there's a remote branch \nnamed that.\n\n> Note: moving to 'branch-g90bc1a6' which isn't a local branch\n> If you want to create a new branch from this checkout, you may do so\n> (now or later) by using -b with the checkout command again. Example:\n>   git checkout -b <new_branch_name>\n> HEAD is now at 90bc1a6... Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus\n> # so where is coming from?\n\nThe official documentaion on specifying revisions is in the man page for \ngit-rev-parse (it's referenced for a bunch of places, although this is \nobviously not the first place you'd think to look).\n\nThe error message should probably be improved to not imply that what's \nalready using that name is a branch.\n\n\t-Daniel\n*This .sig left intentionally blank*\n"}]}