git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: disallowing push to currently checked-out branch

From
Jeff King <peff@peff.net>
Date
Feb 17, 2009, 00:23 UTC
Message-ID
<20090217002352.GA23507@coredump.intra.peff.net>
In-Reply-To
<7vhc2uezl7.fsf@gitster.siamese.dyndns.org>
On Mon, Feb 16, 2009 at 03:23:00PM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> >   1. How can we improve this situation?
> 
> The situation you described is all about "don't allow a push that is NOT
> CONTROLLED BY YOU and that can interfere with what you are doing into a
> live repository", and you are right, we have operations that deliberately
> detach the HEAD and expect nobody mucks with the branch.

I don't agree that it has to be a push not controlled by you. I have many times left a rebase-in-progress sitting in a repository, either accidentally because I meant to "--abort" it after a conflict but forgot, or because I got interrupted during an interactive edit and needed to come back to it.

So the problem is simply that the repository you're pushing into is not in the state you think it is (either because you forgot what state you left it in, didn't realize what state you left it in, or because it is somebody else's repo).

> But is this something even worth considering about in the same context as
> the denyCurrentBranch?  The same thing can happen even if you are not
> detaching HEAD.

I don't think it's the same, but I think it is a related problem. I don't think the solutions are related, though.

Show 17 quoted lines
> For example, I sometimes end up with an ugly series on a branch, whose
> endpoint is a good looking tree.  And a refactoring I would want to do
> would be too cumbersome for the interactive rebase (I could do it, but the
> machinery does not help as much as it would for a simpler case).  In such
> a case, often I would just say:
> 
> 	$ git branch -f goal
>         $ git reset --hard master
>         : repeat from here until "diff HEAD goal" becomes empty
>         ... cherry-pick $a_commit_in_goal_branch, or
>         ... edit "show $a_commit_in_goal_branch" output and apply, or
>         ... edit the files in place.
>         ... make a commit, perhaps using -c $a_commit_in_goal_branch
> 	: repeat up to here
> 
> I would not push into this repository to update the branch "goal" while I
> am doing this, as it will obviously screw up the whole process.  I think

OK, that is a good example of how this is basically impossible to protect from fully (and a good argument why pushing into a repo used for work is probably not a good idea in general). I think the rebase example is a little worse because:

  - It's subtle. with denyCurrentBranch, we generally protect the user
    from pushing into the current branch and messing things up. But
    during a rebase we don't, and the only way the user would realize
    that is if they understand that rebasing happens on a detached HEAD.
  - the error message is confusing, and there is no clear way out of the
    error case. You can "rebase --abort" which throws away your rebase
    work _and_ the push.  But what you probably want to do, I described
    earlier.
> It's just a common sense thing.  What denyCurrentBranch protects you from
> is a push from elsewhere *while* you are not there, and then next day,
> getting confused by what such a push did in the receiving repository.  In

See above for why I think this can happen while you are not there. It is about repo state for long-running workflows. I'm not too concerned with somebody pushing in the exact half second while you are making running "git commit".

> Obviously you can tell receive-pack to refuse pushing into a non-bare
> repository, with a "I know what I am doing" configuration, but I think at
> that point the whole "you could break things this way, so let's prevent a
> new user from making such mistake" goes into the realm of absurdity.

I think that is insane, too. This is not all that likely to happen compared to the possible benefits of pushing into a non-bare repo. And as you say, in most cases common sense rules: don't push into something you are actively working on.

I am really just proposing that the "ref was not what we expected" message to better indicate what is going on, and how the user might get out of it. Do you not agree with that?

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 43 of 91 in “[RFC - draft] List of proposed future changes that are backward incompatible”
  1. Junio C HamanoFeb 15, 2009
  2. Junio C HamanoFeb 15, 2009
  3. Jakub NarebskiFeb 15, 2009
  4. Junio C HamanoFeb 15, 2009
  5. Heikki OrsilaFeb 15, 2009
  6. disallowing push to currently checked-out branchJeff King, Feb 16, 2009
  7. david@lang.hmFeb 16, 2009
  8. david@lang.hmFeb 16, 2009
  9. Julian PhillipsFeb 16, 2009
  10. Jeff KingFeb 16, 2009
  11. Daniel BarkalowFeb 16, 2009
  12. Junio C HamanoFeb 16, 2009
  13. Sergio CallegariFeb 16, 2009
  14. Jeff KingFeb 16, 2009
  15. Sergio CallegariFeb 16, 2009
  16. Matthieu MoyFeb 16, 2009
  17. Johannes SchindelinFeb 16, 2009
  18. Jay SoffianFeb 16, 2009
  19. Johannes SchindelinFeb 16, 2009
  20. Jay SoffianFeb 16, 2009
  21. Johannes SchindelinFeb 16, 2009
  22. Jay SoffianFeb 16, 2009
  23. Jeff KingFeb 16, 2009
  24. Jay SoffianFeb 17, 2009
  25. PUSH_HEAD, was Re: disallowing push to currently checked-out branchJohannes Schindelin, Feb 17, 2009
  26. Jay SoffianFeb 17, 2009
  27. Jeff KingFeb 17, 2009
  28. Junio C HamanoFeb 17, 2009
  29. Jay SoffianFeb 17, 2009
  30. Johannes SchindelinFeb 17, 2009
  31. Sergio CallegariFeb 16, 2009
  32. Johannes SchindelinFeb 16, 2009
  33. Jay SoffianFeb 16, 2009
  34. Sergio CallegariFeb 17, 2009
  35. Johannes SchindelinFeb 17, 2009
  36. Sergio CallegariFeb 17, 2009
  37. Johannes SchindelinFeb 17, 2009
  38. Junio C HamanoFeb 17, 2009
  39. Junio C HamanoFeb 17, 2009
  40. Junio C HamanoFeb 16, 2009
  41. Jeff KingFeb 16, 2009
  42. Junio C HamanoFeb 16, 2009
  43. Jeff KingFeb 17, 2009
  44. Junio C HamanoFeb 17, 2009
  45. Jeff KingFeb 17, 2009
  46. Jeff KingFeb 16, 2009
  47. david@lang.hmFeb 16, 2009
  48. Jeff KingFeb 16, 2009
  49. david@lang.hmFeb 16, 2009
  50. Jeff KingFeb 16, 2009
  51. david@lang.hmFeb 16, 2009
  52. Jeff KingFeb 16, 2009
  53. Johannes SchindelinFeb 16, 2009
  54. dashed commands, was Re: disallowing push to currently checked-out branchJohannes Schindelin, Feb 16, 2009
  55. david@lang.hmFeb 15, 2009
  56. Johannes SchindelinFeb 15, 2009
  57. Junio C HamanoFeb 15, 2009
  58. david@lang.hmFeb 16, 2009
  59. Johannes SchindelinFeb 15, 2009
  60. david@lang.hmFeb 16, 2009
  61. Junio C HamanoFeb 16, 2009
  62. Johannes SchindelinFeb 16, 2009
  63. david@lang.hmFeb 16, 2009
  64. Sverre RabbelierFeb 16, 2009
  65. disallowing push to currently checked-out branchJeff King, Feb 16, 2009
  66. Sergio CallegariFeb 16, 2009
  67. Jakub NarebskiFeb 15, 2009
  68. Johannes SchindelinFeb 15, 2009
  69. Jakub NarebskiFeb 15, 2009
  70. david@lang.hmFeb 16, 2009
  71. send-email sending shallow threads by defaultJeff King, Feb 16, 2009
  72. Pieter de BieFeb 16, 2009
  73. Jeff KingFeb 16, 2009
  74. Brian GernhardtFeb 16, 2009
  75. Wincent ColaiutaFeb 16, 2009
  76. SZEDER GáborFeb 16, 2009
  77. Martin MaresFeb 16, 2009
  78. Andreas EricssonFeb 17, 2009
  79. Martin MaresFeb 17, 2009
  80. Jeff KingFeb 17, 2009
  81. Eric W. BiedermanFeb 20, 2009
  82. Jeff KingFeb 20, 2009
  83. Eric W. BiedermanFeb 20, 2009
  84. Andreas EricssonFeb 17, 2009
  85. Sitaram ChamartyFeb 16, 2009
  86. Björn SteinbrinkFeb 16, 2009
  87. Junio C HamanoFeb 16, 2009
  88. Björn SteinbrinkFeb 16, 2009
  89. [RFC - draft #2] List of proposed future changes that are backward incompatibleJunio C Hamano, Feb 16, 2009
  90. Jeff KingFeb 16, 2009
  91. Jakub NarebskiFeb 16, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.