10

I have a fork of popular repo, I want to be able to keep track of commits being push to that repo while also having my own personal commits to my fork. I don't really want my changes to be merged upstream so I'm fine with merging/rebasing every time someone commits to the upstream repo.

I read about triangle workflow and Magit's support for it and thought it great. It does exactly what I need, except that it insists my local commits should be finally merged into the main repo thus displaying a list of my local commits under the section Unmerged into upstream/master:

Head:     <local commit>
Merge:    upstream/master <upstream commit>
Push:     origin/master <local commit>

Unpulled from upstream/master (1)
987ac90 upstream/master <upstream commit>

Unmerged into upstream/master (1)
123baf8 master origin/master <local commit>

This is fine if there are a couple of commits, but later my personal modifications will pile on and the list will grow. Is there any way to set the section Unmerged into upstream/master to be always hidden?

Ammar Alammar
  • 325
  • 1
  • 7

1 Answers1

9

While no such option existed when this question was asked, it now does: magit-section-initial-visibility-alist.


Old answer:

No option exists to do this easily, mostly because this feature hasn't been requested often. (I cannot remember that it ever was requested before, which I find a bit surprising.) I do intend to eventually add such an option, but not until I make other, more fundamental, changes to the section code.

But a hook exists which can be used to do this. You'll have to write a bit of boilerplate though:

(defun local-magit-initially-hide-unmerged (section)
  (and (not magit-insert-section--oldroot)
       (eq (magit-section-type section) 'unpushed)
       (equal (magit-section-value section) "@{upstream}..")
       'hide))

(add-hook 'magit-section-set-visibility-hook
          'local-magit-initially-hide-unmerged)
  • If magit-insert-section--oldroot is nil then the buffer is being first created (not being updated). We only want to return non-nil in that case.
  • To get the value and type of a section use M-x magit-describe-section.
  • The return value has to be hide, show, or nil (let something else decide).
  • Such functions have to come before magit-section-set-visibility-from-cache in the hook.

That's a bit rough around the edges, then again this was only intended for internal purposes.

tarsius
  • 25,298
  • 4
  • 69
  • 109