Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of orphan branches #2030

Closed
mrkkrp opened this issue Jul 9, 2015 · 22 comments
Closed

Allow creation of orphan branches #2030

mrkkrp opened this issue Jul 9, 2015 · 22 comments
Labels
enhancement New feature or request

Comments

@mrkkrp
Copy link
Contributor

mrkkrp commented Jul 9, 2015

I've done some research before opening the issue, but it seems like currently Magit cannot be used to create an orphan branch. Am I missing something? I've checked the manual and word orphan or --orphan is not mentioned there, thus chances are it's unavailable. I also have searched issues, no luck.

Could you please add an option to do git checkout --orphan my-branch via magit? Thanks.

@tarsius tarsius added the enhancement New feature or request label Jul 9, 2015
@tarsius
Copy link
Member

tarsius commented Jul 9, 2015

I have thought about it in the past, but decided against adding this feature. It would only very rarely be used and so its main effect would be to confuse beginners. I think it's okay to have to drop to the command line once in a while.

@mrkkrp
Copy link
Contributor Author

mrkkrp commented Jul 9, 2015

OK, if it's your decision. By the way, there many things that may confuse beginners. My attitude toward some option that I don't understand is either ignore it until I need it or search for information about it. Personally I don't see how existence of some option may be confusing per se, you just don't use it if you don't know what it is.

I think it's okay to have to drop to the command line once in a while.

I've read something different in description of magit:

Magit aspires to be a complete Git porcelain.

Anyway, it's not a problem for me to open eshell sometimes.

@npostavs
Copy link
Member

npostavs commented Jul 9, 2015

You can always add this yourself with (magit-define-popup-switch 'magit-branch-popup ?o "Create an orphan branch" "--orphan").

@mrkkrp
Copy link
Contributor Author

mrkkrp commented Jul 9, 2015

@npostavs, yeah, in my init file I can do virtually everything. It's also nice when things don't need to be patched to make them do what they might do by default. Thank you for your reply.

@tarsius tarsius added this to the later milestone Jul 9, 2015
@tarsius
Copy link
Member

tarsius commented Jul 9, 2015

Well "complete" isn't the same as "implement each and every conceivable feature". Also note that --orphan was missing from the Git porcelain for a very long time.

Also I plan to improve branching and pushing a lot some time in the future. Unfortunately many users don't seem to be happy with the current feature set. So unhappy in fact, that I will have to make some intermediate changes. But I would like to keep that to a minimum, because I already know it will change again.

Maybe when I write "the real thing" (#1485) in a few months, then this can be reconsidered. Closing in favor of that issue.

@tarsius tarsius closed this as completed Jul 9, 2015
@npostavs
Copy link
Member

npostavs commented Jul 9, 2015

yeah, in my init file I can do virtually everything. It's also nice when things don't need to be patched to make them do what they might do by default.

This seems more like adding a keybinding then a "patch" to me.


Maybe when I write "the real thing" (#1485) in a few months, then this can be reconsidered. Closing in favor of that issue.

Not really seeing how the publish branch thing (which sounds awesome, by the way) is related to this issue.

@tarsius
Copy link
Member

tarsius commented Jul 9, 2015

Not really seeing how the publish branch thing (which sounds awesome, by the way) is related to this issue.

Yeah not really. It's just that I am getting kind of annoyed, that everyone seems to think I have to improve branch/pushing now. I would like to make all changes in the domain at around the same time, on a feature branch, which can be commended on before it is merged to master. This would allow me to avoid adding features now and then later sacrifice them for other, in my opinion more important, features which happen to collide with features added earlier as temporary kludges. But I give up, I am going to add the requested features now, and then later deal with dissatisfied users when/if I remove them again.

@npostavs
Copy link
Member

npostavs commented Jul 9, 2015

everyone seems to think I have to improve branch/pushing now.

Is that really true? From what I've seen, whenever you say "I'll do this later" the issue opener generally responds with something like "ok, there's no rush". Pretty sure I've never seen someone say "NO, DO IT NOW!!".

@tarsius
Copy link
Member

tarsius commented Jul 9, 2015

Is that really true?

No, but since a lot of people are unhappy about the current implementation, it feels like it. While users who have approached me about this now understand and accept that I want to delay this, other users would show up with similar wishes, up to the point when I finally tackle this on my own schedule. Replying to all those inquiries would be a lot of work and a bit stressful. So I have decided to do something about this now - sorry for implying claiming someone forced me to do it. It's the situation which forces me, not people.

Of course all that could have been avoided by delaying the release of 2.1.0 even further, but as we all know it was about time that got out. I just hoped I would have a bit more time to fill in the missing details.

(The current branching and pulling implementation was always just intended as an intermediate, and minimal-viable, implementation. It now turns out that it's not good enough for a released implementation.)

@tarsius
Copy link
Member

tarsius commented Jul 9, 2015

Pretty sure I've never seen someone say "NO, DO IT NOW!!".

It also occurs to me, that I would probably not have implied otherwise, except in this context: "not adding --orphan contradicts your claim 'Magit aspires to be a complete Git porcelain.'", which frankly did annoy me ("you are not living up to your promises"). My careless, and factually wrong, wording should be seen in light of this.

@tarsius
Copy link
Member

tarsius commented Sep 24, 2015

@tarsius tarsius modified the milestones: 2.2.0, later Sep 24, 2015
@tarsius tarsius added wont add This feature will not be worked on and removed enhancement New feature or request labels Sep 24, 2015
@npostavs
Copy link
Member

Done.

@alxempirical
Copy link

@npostavs:

You can always add this yourself with (magit-define-popup-switch 'magit-branch-popup ?o "Create an orphan branch" "--orphan").

This doesn't work. b -o c results in it querying for the parent branch, and then a command like git checkout --orphan -b child-branch master.

@npostavs
Copy link
Member

npostavs commented Jun 6, 2016

oh, right, I misunderstood how --orphan actually works. Looks a patch would be needed after all. Something like this?

modified   lisp/magit.el
@@ -1358,7 +1358,11 @@ (defun magit-branch-and-checkout (branch start-point &optional args)
   (interactive (magit-branch-read-args "Create and checkout branch"))
   (if (string-match-p "^stash@{[0-9]+}$" start-point)
       (magit-run-git "stash" "branch" branch start-point)
-    (magit-call-git "checkout" args "-b" branch start-point)
+    (magit-call-git "checkout" (if (member "--orphan" args)
+                                   (cl-list* "--orphan" branch
+                                             (delete "--orphan" args))
+                                 (cl-list* "-b" branch args))
+                    start-point)
     (--when-let (and (magit-get-upstream-branch branch)
                      (magit-get-indirect-upstream-branch start-point))
       (magit-call-git "branch" (concat "--set-upstream-to=" it) branch))

@alxempirical
Copy link

alxempirical commented Jun 6, 2016

@npostavs: Thanks for that, not bad. It still asks for a parent branch, but I guess one could put a similar condition in whatever code is doing that.

@tarsius
Copy link
Member

tarsius commented Jun 6, 2016

I'm okay with adding magit-branch-orphan or something like that now. Not sure whether we should add it to the popup by default, but providing this as a separate command seems more reasonable than teaching existing commands about --orphan (because of the complications involved in the latter).

@alxempirical
Copy link

I would advise against adding it to the popup. git branch --orphan leaves the working tree in a state which is going to cause a fair amount of anxiety in inexperienced users: The whole tree is still present and staged, and for this reason getting back with git checkout master requires -f. It would probably lead to a lot of support questions.

@tarsius
Copy link
Member

tarsius commented Jun 6, 2016

I agree.

@tarsius tarsius removed this from the 2.2.0 milestone Jun 6, 2016
@tarsius tarsius added enhancement New feature or request and removed wont add This feature will not be worked on labels Jun 6, 2016
@tarsius tarsius reopened this Jun 6, 2016
@npostavs
Copy link
Member

npostavs commented Jun 7, 2016

providing this as a separate command seems more reasonable than teaching existing commands about --orphan (because of the complications involved in the latter).

Yeah, most of the things in magit-branch-and-checkout don't make sense with --orphan.

Could be just

(defun magit-branch-orphan (branch start-point &optional args)
  "Create and checkout an orphan BRANCH with contents from revision START-POINT.
\n(git checkout [ARGS] --orphan BRANCH START-POINT)."
  (interactive (magit-branch-read-args "Create and checkout orphan branch"))
  (magit-run-git "checkout" args "--orphan" branch start-point))

tarsius added a commit that referenced this issue Jun 9, 2016
@tarsius
Copy link
Member

tarsius commented Jun 9, 2016

I've added that command and updated the wiki.

@tarsius tarsius closed this as completed Jun 9, 2016
@untoreh
Copy link

untoreh commented Mar 28, 2018

can it be added to the popup by enabling an option?

@tarsius
Copy link
Member

tarsius commented Mar 28, 2018

Not an option but a function: https://magit.vc/manual/magit-popup/Customizing-Existing-Popups.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

5 participants