{"thread":{"id":"43152","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","startedAt":"2006-12-07T10:01:52Z","lastAt":"2006-12-08T15:39:31Z","messageCount":12,"participants":["Junio C Hamano","J. Bruce Fields","Shawn Pearce","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"297529","messageId":"20061207100152.GA12966@spearce.org","threadId":"43152","inReplyTo":null,"subject":"[PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-07T10:01:52Z","receivedAt":"2006-12-07T10:01:52Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"I have recently observed a rather large number of users who forget\nto specify the base revision when they start a new branch with\ngit-checkout -b.  Many of these users are shocked many hours and\ncommits later when their prior branch is now also part of the new\nbranch.  Nasty words about Git usually follow the discovery.\n\nThis introduces a new config option: checkout.requireSourceBranch,\nwhich the user can set to make git-checkout -b require them to supply\nnot only the new branch name but also the initial version for that\nbranch.  This prevents the command from assuming the user meant HEAD\nwhen they omitted an argument by accident.\n\nTo keep behavior backwards compatible with any existing scripts\nthis option is currently disabled by default, but it would be more\nfriendly to new users if the option was enabled by default.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Documentation/config.txt |    6 ++++++\n git-checkout.sh          |   12 +++++++++++-\n t/t3200-branch.sh        |   14 ++++++++++++++\n 3 files changed, 31 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 9090762..9d754c8 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -130,6 +130,12 @@ branch.<name>.merge::\n \tWhen in branch <name>, it tells `git fetch` the default remote branch\n \tto be merged.\n \n+checkout.requireSourceBranch::\n+\tIf true tells git-checkout -b to require the user to\n+\tsupply two arguments, rather than assuming HEAD should\n+\tbe the source version if only one argument is supplied.\n+\tDefault is false, to stay compatible with prior behavior.\n+\n pager.color::\n \tA boolean to enable/disable colored output when the pager is in\n \tuse (default is true).\ndiff --git a/git-checkout.sh b/git-checkout.sh\nindex 737abd0..5f9fb6e 100755\n--- a/git-checkout.sh\n+++ b/git-checkout.sh\n@@ -137,7 +137,17 @@ then\n \tcd \"$cdup\"\n fi\n \n-[ -z \"$new\" ] && new=$old && new_name=\"$old_name\"\n+# If we have no new name default to 'HEAD', unless we are\n+# making a new branch and the user told us not to assume.\n+if [ -z \"$new\" ]; then\n+\tif [ \"$newbranch\" ] &&\n+\t   [ Xtrue = \"X`git-repo-config --bool checkout.requireSourceBranch`\" ]\n+\tthen\n+\t\tdie \"A source branch is required when creating a branch.\"\n+\tfi\n+\tnew=$old\n+\tnew_name=\"$old_name\"\n+fi\n \n # If we don't have an old branch that we're switching to,\n # and we don't have a new branch name for the target we\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex acb54b6..7e0c48b 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -70,4 +70,18 @@ test_expect_success \\\n         git-branch -d l/m &&\n         git-branch l'\n \n+test_expect_success \\\n+\t'git checkout -b M works if checkout.requireSourceBranch not set' \\\n+\t'git-checkout -b M'\n+\n+test_expect_failure \\\n+\t'git checkout -b N fails if checkout.requireSourceBranch is set' \\\n+\t'git-repo-config checkout.requireSourceBranch true\n+\t git-checkout -b N'\n+\n+test_expect_success \\\n+\t'git checkout -b N works if checkout.requireSourceBranch is false' \\\n+\t'git-repo-config checkout.requireSourceBranch false\n+\t git-checkout -b N'\n+\n test_done\n-- \n1.4.4.2.gb772\n"},{"id":"293934","messageId":"7vlkljsd1k.fsf@assigned-by-dhcp.cox.net","threadId":"43152","inReplyTo":"20061207100152.GA12966@spearce.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-07T19:48:07Z","receivedAt":"2006-12-07T19:48:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> I have recently observed a rather large number of users who forget\n> to specify the base revision when they start a new branch with\n> git-checkout -b.  Many of these users are shocked many hours and\n> commits later when their prior branch is now also part of the new\n> branch.  Nasty words about Git usually follow the discovery.\n>\n> This introduces a new config option: checkout.requireSourceBranch,\n\nI'm not sure about this.\n\nOften after you started to code something while on 'master' you\nrealize that work is not trivial and needs its own branch and\nthen \"checkout -b\" without having to say 'master' (or HEAD) is\nvery handy.\n\nI think requring an explicit fork-point when you are _not_ on\n'master' might be a better behaviour.\n\nIn other words, you allow \"checkout -b\" (and \"branch\") to\ndefault to HEAD only while on the branches marked in your\nconfiguration file:\n\nThen:\n\n\t[branch]\n        \tallowbranchbydefault = main\n        \tallowbranchbydefault = test\n\ncan be used to say \"while on 'main' and 'test' branch, 'git\ncheckout -b' and 'git branch' without branch point defaults to\nthe current branch\".\n\nYou could turn it around and make it a per-branch configuration,\nlike:\n\n\t[branch \"main\"]\n        \tallowbranchbydefault = true\n\n"},{"id":"297211","messageId":"20061207195715.GG12143@spearce.org","threadId":"43152","inReplyTo":"7vlkljsd1k.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-07T19:57:15Z","receivedAt":"2006-12-07T19:57:15Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> > This introduces a new config option: checkout.requireSourceBranch,\n> \n> You could turn it around and make it a per-branch configuration,\n> like:\n> \n> \t[branch \"main\"]\n>         \tallowbranchbydefault = true\n\nAre you suggesting that we change \"git-checkout -b\" to by default\nrequire the source branch, but the user can restore the original\nbehavior by setting the above per-branch configuration option?\n\nI'm OK with that version too.  Most of these users want to be\nrequired to enter the source branch, and their topic branches (which\nare always their current branches btw) are so transient they won't\nbother with a per-branch setting.  So they get what they want:\nthe tool reminding them to select their source revision.\n\n-- \n"},{"id":"297156","messageId":"7v64cns8nf.fsf@assigned-by-dhcp.cox.net","threadId":"43152","inReplyTo":"20061207195715.GG12143@spearce.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-07T21:23:00Z","receivedAt":"2006-12-07T21:23:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n> Junio C Hamano <junkio@cox.net> wrote:\n>> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n>> > This introduces a new config option: checkout.requireSourceBranch,\n>> \n>> You could turn it around and make it a per-branch configuration,\n>> like:\n>> \n>> \t[branch \"main\"]\n>>         \tallowbranchbydefault = true\n>\n> Are you suggesting that we change \"git-checkout -b\" to by default\n> require the source branch, but the user can restore the original\n> behavior by setting the above per-branch configuration option?\n\nUnder my suggestion, the new git-checkout -b (and git-branch)\nwould:\n\n (0) proceed if there is an explicit branch point specified on\n     the command like, just like now;\n\n (1) allow omission of branch-point if the current branch has\n     allowbranchbydefault configuration set as in above.  A new\n     branch is created forking off of the current HEAD;\n\n (2) allow omission of branch-point if no branch has such\n     configuration; in other words, existing repositories that\n     do not have the allowbranchbydefault configuration anywhere\n     are not affected.  A new branch is created forking off of\n     the current HEAD;\n\n (3) otherwise, it barfs if you do not give an explicit\n     branch-point.\n\nand a newly created repository that is newbie friendly has one\nsuch configuration automatically set for 'master' (if created\nwith git-init) or whatever the primary branch is (if created\nwith git-clone).\n\nNote that (2) is rather important, although I think the current\nimplementation of repo-config is cumbersome to use for this\npurpose and probably needs to be enhanced.\n\n"},{"id":"298276","messageId":"20061207214053.GC31035@fieldses.org","threadId":"43152","inReplyTo":"7v64cns8nf.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-12-07T21:40:53Z","receivedAt":"2006-12-07T21:40:53Z","isPatch":true,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Thu, Dec 07, 2006 at 01:23:00PM -0800, Junio C Hamano wrote:\n> Under my suggestion, the new git-checkout -b (and git-branch)\n> would:\n> \n>  (0) proceed if there is an explicit branch point specified on\n>      the command like, just like now;\n> \n>  (1) allow omission of branch-point if the current branch has\n>      allowbranchbydefault configuration set as in above.  A new\n>      branch is created forking off of the current HEAD;\n> \n>  (2) allow omission of branch-point if no branch has such\n>      configuration; in other words, existing repositories that\n>      do not have the allowbranchbydefault configuration anywhere\n>      are not affected.  A new branch is created forking off of\n>      the current HEAD;\n> \n>  (3) otherwise, it barfs if you do not give an explicit\n>      branch-point.\n> \n> and a newly created repository that is newbie friendly has one\n> such configuration automatically set for 'master' (if created\n> with git-init) or whatever the primary branch is (if created\n> with git-clone).\n\nThat makes the default behavior more complicated to explain.  Is there\nreally sufficient evidence that this a serious problem?\n\n"},{"id":"297077","messageId":"20061207215914.GC12502@spearce.org","threadId":"43152","inReplyTo":"20061207214053.GC31035@fieldses.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-07T21:59:14Z","receivedAt":"2006-12-07T21:59:14Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"J. Bruce Fields\" <bfields@fieldses.org> wrote:\n> On Thu, Dec 07, 2006 at 01:23:00PM -0800, Junio C Hamano wrote:\n> > Under my suggestion, the new git-checkout -b (and git-branch)\n> > would:\n> > \n[snip]\n> \n> That makes the default behavior more complicated to explain.  Is there\n> really sufficient evidence that this a serious problem?\n\nI'm seeing bad branches all to often with some of the folks I have\nto work with.  They apparently have been unable to learn the new\ntrick of either remembering what branch they are currently on and\nwhat changes it has, or to always supply the branch they want to\nstart from with their new branch.\n\nConsequently they are cussing at Git rather often, as \"this damn\nGit crap always does the wrong with my files\".  Despite it being\ntheir own fault for not thinking before doing...\n\nOf course many of these users also don't understand the value of a\ngood short diff for a simple change.  *sigh*  But right now I just\nwant to stop them from creating branches off the wrong branch point\n95% of the time.\n\n-- \n"},{"id":"295163","messageId":"20061208044516.GC5939@fieldses.org","threadId":"43152","inReplyTo":"20061207215914.GC12502@spearce.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-12-08T04:45:16Z","receivedAt":"2006-12-08T04:45:16Z","isPatch":true,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Thu, Dec 07, 2006 at 04:59:14PM -0500, Shawn Pearce wrote:\n> I'm seeing bad branches all to often with some of the folks I have\n> to work with.  They apparently have been unable to learn the new\n> trick of either remembering what branch they are currently on and\n> what changes it has, or to always supply the branch they want to\n> start from with their new branch.\n\nWell, it's true that \"git branch\" is the first thing I type whenever I\nsit down, just to remember where I am....\n\nWould the trick of putting the branch name in the shell prompt work?\n\n> Consequently they are cussing at Git rather often, as \"this damn\n> Git crap always does the wrong with my files\".  Despite it being\n> their own fault for not thinking before doing...\n> \n> Of course many of these users also don't understand the value of a\n> good short diff for a simple change.  *sigh*  But right now I just\n> want to stop them from creating branches off the wrong branch point\n> 95% of the time.\n\nBut my main complaint is just that I wouldn't want to see the behavior\nof defaulting to HEAD--behavior which is simple, easy to explain, and\nshared by most other git commands--by something significantly more\ncomplicated.  That's more a complaint about Junio's suggestion than\nyours, though.\n\n"},{"id":"296184","messageId":"20061208055938.GB13999@spearce.org","threadId":"43152","inReplyTo":"20061208044516.GC5939@fieldses.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-08T05:59:38Z","receivedAt":"2006-12-08T05:59:38Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"J. Bruce Fields\" <bfields@fieldses.org> wrote:\n> On Thu, Dec 07, 2006 at 04:59:14PM -0500, Shawn Pearce wrote:\n> > I'm seeing bad branches all to often with some of the folks I have\n> > to work with.  They apparently have been unable to learn the new\n> > trick of either remembering what branch they are currently on and\n> > what changes it has, or to always supply the branch they want to\n> > start from with their new branch.\n> \n> Would the trick of putting the branch name in the shell prompt work?\n\nIts in the prompt for all of these users; I forced it in as part of\nthe system's /etc/profile.d.  They just forget that they should think\nabout where they should start their branch from before they make it.\n \n> But my main complaint is just that I wouldn't want to see the behavior\n> of defaulting to HEAD--behavior which is simple, easy to explain, and\n> shared by most other git commands--by something significantly more\n> complicated.  That's more a complaint about Junio's suggestion than\n> yours, though.\n\nTrue, defaulting to HEAD is something that is done almost everywhere.\nChanging it for `git checkout -b` may surprise a lot of people,\nalmost as much as --index vs. --cached.\n\nMaybe what I should do is stop whining about the command line\nPorcelain-ish and get branch controls working in git-gui.  Then I\ncan take away the command line from these users who are causing me\nso much grief.\n\n-- \n"},{"id":"297404","messageId":"20061208060850.GE5939@fieldses.org","threadId":"43152","inReplyTo":"20061208055938.GB13999@spearce.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-12-08T06:08:50Z","receivedAt":"2006-12-08T06:08:50Z","isPatch":true,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Fri, Dec 08, 2006 at 12:59:38AM -0500, Shawn Pearce wrote:\n> Its in the prompt for all of these users; I forced it in as part of\n> the system's /etc/profile.d.  They just forget that they should think\n> about where they should start their branch from before they make it.\n\nMaybe they don't really want to use topic branches at all?  Could they\nget away with just committing everything to master?  Seems like kind of\na shame, though.  Hm.\n\n"},{"id":"296456","messageId":"20061208061916.GF13999@spearce.org","threadId":"43152","inReplyTo":"20061208060850.GE5939@fieldses.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-08T06:19:16Z","receivedAt":"2006-12-08T06:19:16Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"\"J. Bruce Fields\" <bfields@fieldses.org> wrote:\n> On Fri, Dec 08, 2006 at 12:59:38AM -0500, Shawn Pearce wrote:\n> > Its in the prompt for all of these users; I forced it in as part of\n> > the system's /etc/profile.d.  They just forget that they should think\n> > about where they should start their branch from before they make it.\n> \n> Maybe they don't really want to use topic branches at all?  Could they\n> get away with just committing everything to master?  Seems like kind of\n> a shame, though.  Hm.\n\nGood idea.  But...\n\nNo, because they are working on at least two different unrelated\nchanges at once, and we aren't sure which will graduate into the\ntesting environment first.  If the unrelated changes are intermingled\non the same branch then moving one moves both; and often at least\none of those unrelated changes isn't functioning right and could\ncause headaches for the testing team.\n\n-- \n"},{"id":"297549","messageId":"7vac1yoq3r.fsf@assigned-by-dhcp.cox.net","threadId":"43152","inReplyTo":"20061208055938.GB13999@spearce.org","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-12-08T06:31:52Z","receivedAt":"2006-12-08T06:31:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Shawn Pearce <spearce@spearce.org> writes:\n\n>> But my main complaint is just that I wouldn't want to see the behavior\n>> of defaulting to HEAD--behavior which is simple, easy to explain, and\n>> shared by most other git commands--by something significantly more\n>> complicated.  That's more a complaint about Junio's suggestion than\n>> yours, though.\n>\n> True, defaulting to HEAD is something that is done almost everywhere.\n> Changing it for `git checkout -b` may surprise a lot of people,\n> almost as much as --index vs. --cached.\n\nI did not mean to change the default to something other than\nHEAD depending on the configuration.\n\n> (0) proceed if there is an explicit branch point specified on\n>     the command like, just like now;\n\n... which is the same as before.\n\n> (1) allow omission of branch-point if the current branch has\n>     allowbranchbydefault configuration set as in above.  A new\n>     branch is created forking off of the current HEAD;\n\n... which allows people to do the same as before, but only on\nselected \"primary\" branches;\n\n> (2) allow omission of branch-point if no branch has such\n>     configuration; in other words, existing repositories that\n>     do not have the allowbranchbydefault configuration anywhere\n>     are not affected.  A new branch is created forking off of\n>     the current HEAD;\n\n... which allows people to keep using the current behaviour in\nexisting repositories;\n\n> (3) otherwise, it barfs if you do not give an explicit\n>     branch-point.\n\n... but a newly created repositories would have an\nallowbranchbydefault entry on \"master\" (and only on \"master\"),\nwhich means new people would be prevented from making mistakes\nwhen on a non-master branch 'foo':\n\n\t$ git branch bar\n\nand end up a foobar branch that is not based on 'master'.  They\nwill instead get an error message that says \"Hey, are you sure\nyou want to fork off of this branch 'foo'?\"\n\nBut I do not deeply care about this.  An option to disable\n\"default to HEAD\" altogether is fine.\n"},{"id":"294244","messageId":"20061208153931.GA14378@fieldses.org","threadId":"43152","inReplyTo":"7vac1yoq3r.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 1/2] Allow users to require source branch on git-checkout -b.","fromName":"J. Bruce Fields","fromEmail":"bfields@fieldses.org","sentAt":"2006-12-08T15:39:31Z","receivedAt":"2006-12-08T15:39:31Z","isPatch":true,"sender":{"key":"bfields@citi.umich.edu","avatar":null},"body":"On Thu, Dec 07, 2006 at 10:31:52PM -0800, Junio C Hamano wrote:\n> Shawn Pearce <spearce@spearce.org> writes:\n> \n> >> But my main complaint is just that I wouldn't want to see the behavior\n> >> of defaulting to HEAD--behavior which is simple, easy to explain, and\n> >> shared by most other git commands--by something significantly more\n> >> complicated.  That's more a complaint about Junio's suggestion than\n> >> yours, though.\n> >\n> > True, defaulting to HEAD is something that is done almost everywhere.\n> > Changing it for `git checkout -b` may surprise a lot of people,\n> > almost as much as --index vs. --cached.\n> \n> I did not mean to change the default to something other than\n> HEAD depending on the configuration.\n\nRight, I understand that behavior in existing repositories is not\nchanged...\n\n> > (3) otherwise, it barfs if you do not give an explicit\n> >     branch-point.\n> \n> ... but a newly created repositories would have an\n> allowbranchbydefault entry on \"master\" (and only on \"master\"),\n> which means new people would be prevented from making mistakes\n> when on a non-master branch 'foo':\n\n... my concern is the default behavior on newly created repositories,\nwhich (unless I've misunderstood) would become more complicated.\n\n> But I do not deeply care about this.\n\nOK.  Me neither, to be honest.\n\n"}]}