3

I recently started using magit package in emacs and its really useful and handy. I would like to make couple of tweaks.

How do I make magit pull to be always have rebase option?. Currently it shows up switches and I have to choose -r --rebase. In my dev process, we always rebase.

I use gtags+global for code browsing. Upon magit pull, It would be great if I can have a hook to rebuild the gtags again. Is there hook after git pull success ?.

sudurais
  • 189
  • 1
  • 7
  • One could argue that you should change your development process to have close to no need for merging/rebasing on `git pull`. Don't work on a shared branch, but create your own feature branches. –  Nov 24 '13 at 08:52
  • Note, in Magit 2 this is built-in to all commands. Just open the popup for the mode, set the option, and then `C-x C-s` to save them as default. –  Apr 03 '16 at 22:55

3 Answers3

4

I do not know any Magit-specific setting, but you can just configure git itself accordingly:

git config --global pull.rebase true

I'd strictly advise against on enabling this setting globally.

As I have said in my comment, you should really change your development process so that there is no need for merging/rebasing on git pull. Don't work on shared branches, but instead always create your own feature branches for your work, and explicitly merge when needed.

You can then explicitly configure individual shared branches in your repository for rebasing, e.g.

git config --local branch.my-fancy-feature.rebase true

As for the hook, there is no specific hook for git pull. However, there is no harm in updating the tags file on other changes to the tree as well, so you may just the post-rewrite (for git rebase) and post-merge (for git merge) hooks.

See Tim Pope's post Effortless Ctags with Git for details on such a setup.

  • thanks for the input. i'm looking for magit solution since i use it alot within emacs. About gtags update, i found this solution. https://github.com/rvoicilas/inotify-tools/wiki It can update the if any of the file modified. – sudurais Nov 25 '13 at 20:50
  • Magit maintainer here. There is no magit-specific option for this and I don't think it would be a good idea to add one. (If we add an elisp option here, why not for every other git variable?). Setting this locally using git-config as @lunaryorn suggested is a good solution. Alternatively you should just use the rebase command (`R`). Like the merge command (`m`) that defaults to bringing in the changes from the configured upstream branch. – tarsius Dec 30 '13 at 01:45
  • I have a question, which I think is related. In the popup invoked by l(og), there is "-al: All (--all)" switch. Is there a way to make this on by default through configuration? I was able to do it via editing magit-key-mode-generate function in the magit-key-mode.el like (logging '(list "--graph" "--all")) But I would like to avoid editing the original file. – kaz_yos Feb 12 '14 at 21:35
  • 1
    I was actually able to do it in a slightly better way by redefining the popup function (magit-key-mode-popup-logging) in my init.el. But I think its nice to have toggles for these hard-coded (as I think) options. https://github.com/kaz-yos/emacs/blob/master/init.el#L1879..L1887 – kaz_yos Feb 12 '14 at 22:07
2

This code will do what you want and make it easy to add default options for more modes:

(defun magit-key-mode--add-default-options (arguments)
  (let* ((mode (car arguments))
         (options (cadr arguments))
         (default-options (cdr (assoc mode my/magit-default-options))))
    (list mode (delete-dups (delq nil (append options default-options))))))

(setq my/magit-default-options
      `(
        (pulling "--rebase")
        ))

(advice-add 'magit-key-mode :filter-args #'magit-key-mode--add-default-options)

Note: This should be an edit to doublep's answer, but 3-out-of-4 wonks rejected the edit. Not one of them has even touched Emacs.SE, nor do they have any mention of Emacs or Lisp on their SO or LinkedIn profiles. Clearly, people who don't know the language in question should not be endowed with the power to reject edits.

I came here looking for an answer to this question, found doublep's answer, improved it by making the code clearer and extensible, and spent my own valuable time contributing the improvements back to the community, only to have it shot down by people who don't even know what they're doing. Every time this happens (and, so far, it has happened every time), I wonder why I'm wasting my time contributing to this site.

Community
  • 1
  • 1
1

Add the following to your .emacs:

(defun magit-key-mode--add-default-options (arguments)
  (if (eq (car arguments) 'pulling)
      (list 'pulling (list "--rebase"))
    arguments))
(advice-add 'magit-key-mode :filter-args #'magit-key-mode--add-default-options)