{"thread":{"id":"7499","subject":"git-cvsimport does not like detached HEAD","startedAt":"2007-04-03T08:23:37Z","lastAt":"2007-04-04T21:40:18Z","messageCount":2,"participants":["Junio C Hamano","Martin Langhoff"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"38498","messageId":"7vmz1pzx12.fsf@assigned-by-dhcp.cox.net","threadId":"7499","inReplyTo":null,"subject":"git-cvsimport does not like detached HEAD","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-03T08:23:37Z","receivedAt":"2007-04-03T08:23:37Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"In my day-job project, I use git-cvsimport with -i option to\ntreat the central CVS repository as if it is just a branch in a\nremote git repository.  Since I hoard many changes in my git\nrepository and trickle only a few changes at a time to the\ncentral CVS back, I keep shuffling and rebasing my commits on\ntop of what I obtain from CVS, and many times, my HEAD is\ndetached and not on a particular branch.\n\nHowever, it seems git-cvsimport does not like to work when your\nHEAD is detached.\n\nHere is a minimum patch that seems to let me going, but I am not\nquite sure what the implication is for letting orig_branch (and\nlast_branch) to default to \"master\" (I do not use \"master\"\nbranch for that project so maybe I am getting lucky).\n\n---\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 1a1ba7b..a64219f 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -563,8 +563,11 @@ unless (-d $git_dir) {\n \n \topen(F, \"git-symbolic-ref HEAD |\") or\n \t\tdie \"Cannot run git-symbolic-ref: $!\\n\";\n-\tchomp ($last_branch = <F>);\n-\t$last_branch = basename($last_branch);\n+\t$last_branch = <F>;\n+\tif (defined $last_branch) {\n+\t\tchomp($last_branch);\n+\t\t$last_branch = basename($last_branch);\n+\t}\n \tclose(F);\n \tunless ($last_branch) {\n \t\twarn \"Cannot read the last branch name: $! -- assuming 'master'\\n\";\n"},{"id":"38660","messageId":"46141B42.4080102@catalyst.net.nz","threadId":"7499","inReplyTo":"7vmz1pzx12.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-cvsimport does not like detached HEAD","fromName":"Martin Langhoff","fromEmail":"martin@catalyst.net.nz","sentAt":"2007-04-04T21:40:18Z","receivedAt":"2007-04-04T21:40:18Z","isPatch":false,"sender":{"key":"martin@laptop.org","avatar":null},"body":"Junio C Hamano wrote:\n> In my day-job project, I use git-cvsimport with -i option to\n> treat the central CVS repository as if it is just a branch in a\n> remote git repository.  Since I hoard many changes in my git\n> repository and trickle only a few changes at a time to the\n> central CVS back, I keep shuffling and rebasing my commits on\n> top of what I obtain from CVS, and many times, my HEAD is\n> detached and not on a particular branch.\n\nI don't quite understand detached HEAD very well so my reply may be\nbogus... (I'm familiar with cg-seek, which seems to be a similar concept\nof checking out an arbitrary commit in a mode where you are not allowed\nto commit because you are not really at the tip of any branch).\n\n> However, it seems git-cvsimport does not like to work when your\n> HEAD is detached.\n\nYep - I can see how...\n\n> Here is a minimum patch that seems to let me going, but I am not\n> quite sure what the implication is for letting orig_branch (and\n> last_branch) to default to \"master\" (I do not use \"master\"\n> branch for that project so maybe I am getting lucky).\n\ncvsimport should never write to 'master'*, so setting $last_branch to\nmaster will mean that it will always switch to the branch it's importing\n(and the switch will do the initialisation of temp index files, etc).\nYou could set it to '' and get the same effect, perhaps even safer.\n\n* unless the cvs repo has a branch called 'master', and in that case\nwe're fsck'd.\n\nWhich leads me to think -- how magic is master anyway. Should we protect\nit? The CVS repo could have a branchname collision with us on any\nrefname -- always make sure that repos where I do cvsimport are never\ndevelopment repositories, which means that my dev branches are protected\nfrom collisions. I think it's the only sane thing to do.\n\nOTOH, it's trivial to say something like (warning, MUA-broken patch)\n\ndiff --git a/git-cvsimport.perl b/git-cvsimport.perl\nindex 1a1ba7b..73e0544 100755\n--- a/git-cvsimport.perl\n+++ b/git-cvsimport.perl\n@@ -685,6 +685,9 @@ my (@old,@new,@skipped,%ignorebranch);\n # commits that cvsps cannot place anywhere...\n $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;\n\n+# protect 'master';\n+$ignorebranch{'master'} = 1;\n+\n sub commit {\n        if ($branch eq $opt_o && !$index{branch} &&\n!get_headref($branch, $git_dir)) {\n            # looks like an initial commit\n\n\ncheers,\n\n\nm\n-- \n-----------------------------------------------------------------------\nMartin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington\nWEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St\nOFFICE: +64(4)916-7224  UK: 0845 868 5733 ext 7224  MOB: +64(21)364-017\n      Make things as simple as possible, but no simpler - Einstein\n-----------------------------------------------------------------------\n"}]}