Move git packages to git layer

This commit is contained in:
syl20bnr 2014-12-13 23:59:02 -05:00
parent 59286d8ea4
commit f4b97397dc
8 changed files with 324 additions and 273 deletions

163
contrib/git/README.md Normal file
View File

@ -0,0 +1,163 @@
# git contribution layer for Spacemacs
![logo](git.png)
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**
- [git contribution layer for Spacemacs](#git-contribution-layer-for-spacemacs)
- [Description](#description)
- [Install](#install)
- [Working with Git](#working-with-git)
- [Magit](#magit)
- [Quick guide for recurring use cases in Magit](#quick-guide-for-recurring-use-cases-in-magit)
- [Git gutter bitmaps](#git-gutter-bitmaps)
<!-- markdown-toc end -->
## Description
This layers adds extensive for [git][].
Features:
- git repository management the indispensable [magit][] package
- [git-flow][] add-on for magit.
- quick in buffer history browsing with [git-timemachine][]
- quick in buffer last commit message per line with [git-messenger][]
- colorize buffer line by age of commit with [smeargle][]
- git gutter in fringe with [git-gutter][]
## Install
To use this contribution add it to your `~/.spacemacs`
```elisp
(setq-default dotspacemacs-configuration-layers '(git)
"List of contribution to load."
)
```
Of course if your OS does not ship with git (!) you'll have to install it
on your machine, [download page][].
## Working with Git
Git commands (start with `g`):
Key Binding | Description
---------------------------|------------------------------------------------------------
<kbd>SPC g c c</kbd> | highlight regions by age of commits
<kbd>SPC g c C</kbd> | clear highlights
<kbd>SPC g c t</kbd> | highlight regions by last updated time
<kbd>SPC g s</kbd> | open a `magit` status window
<kbd>SPC g m</kbd> | display the last commit message of the current line
<kbd>SPC g t</kbd> | launch the git time machine
- Highlight by age of commit or last update time is provided by
[smeargle][].
- Git time machine is provided by [git-timemachine][].
- Git last commit message per line is provided by
[git-messenger][]
### Magit
`Spacemacs` uses [magit][] to manage Git repositories.
To open a `status buffer`, type in a buffer of a Git repository:
<SPC> g s
`hjkl` navigation is enabled in all Magit buffers. The default Magit keys
on `hjkl` are remapped on `HJKL`.
Here are the often used bindings inside a `status buffer`:
Key Binding | Description
------------------|------------------------------------------------------------
<kbd>/</kbd> | evil-search
<kbd>$</kbd> | open `command output buffer`
<kbd>c c</kbd> | open a `commit message buffer`
<kbd>b b</kbd> | checkout a branch
<kbd>b c</kbd> | create a branch
<kbd>b v</kbd> | open the `branch manager buffer`
<kbd>f f</kbd> | fetch changes
<kbd>F -r F</kbd> | pull and rebase
<kbd>h</kbd> | go left
<kbd>j</kbd> | go down
<kbd>C-j</kbd | goto next magit section
<kbd>k</kbd> | go up
<kbd>K</kbd> | discard changes
<kbd>C-k</kbd | goto previous magit section
<kbd>l</kbd> | go right
<kbd>L l</kbd> | open `log buffer`
<kbd>n</kbd> | next search occurrence
<kbd>C-n</kbd | goto next magit section
<kbd>N</kbd> | previous search occurrence
<kbd>P P</kbd> | push
<kbd>C-p</kbd | goto previous magit section
<kbd>q</kbd> | quit
<kbd>s</kbd> | on a file or hunk in a diff: stage the file or hunk
<kbd>+</kbd> | on a hunk: increase hunk size
<kbd>-</kbd> | on a hunk: decrease hunk size
<kbd>S</kbd> | stage all
<kbd>TAB</kbd> | on a file: expand/collapse diff
<kbd>u</kbd> | on a staged file: unstage
<kbd>U</kbd> | unstage all staged files
<kbd>v</kbd> | `visual state`
<kbd>V</kbd> | `visual-line state`
<kbd>C-v</kbd> | revert item at point
<kbd>z z</kbd> | stash changes
In a commit message buffer press `C-c C-c` to commit the changes with the
entered message. `C-c C-k` will discard the commit message.
**Note:** Sometimes you will be asked about reverting the commit buffer,
you can answer `y` with no issue.
### Quick guide for recurring use cases in Magit
- Amend a commit:
- `L l` to open `log buffer`
- `c a` on the commit you want to amend
- `C-c C-c` to submit the changes
- Squash last commit:
- `L l` to open `log buffer`
- `E` on the second to last commit, it opens the `rebase buffer`
- `j` to put point on last commit
- `i` to pass in `insert state`
- `s` to squash it
- `C-c C-c` to continue to the `commit message buffer`
- `C-c C-c` again when you have finished to edit the commit message
- Force push a squashed commit:
- in the `status buffer` you should see the new commit unpushed and the
old commit unpulled
- `P -f P` for force a push (**beware** usually it is not recommended to
rewrite the history of a public repository, but if you are *sure* that you
are the only one to work on a repository it is ok - i.e. in your fork).
- Add upstream remote (the parent repository you have forked):
- `b v` to open the `branch manager buffer`
- `a` to add a remote, type the name (i.e. `upstream`) and the URL
- Pull changes from upstream (the parent repository you have forked) and push:
- `F -r C-u F` and choose `upstream` or the name you gave to it
- `P P` to push the commit to `origin`
### Git gutter bitmaps
`Spacemacs` has custom fringe bitmaps for
[git-gutter-fringe][git-gutter]:
Symbol | Description
:-------------------------------:|-----------------
![git-new](git-new-line.png) | new line
![git-del](git-del-line.png) | at least one line has been deleted
![git-mod](git-mod-line.png) | modified line
[git]: http://git-scm.com/
[download page]: http://git-scm.com/downloads
[git-gutter]: https://github.com/syohex/emacs-git-gutter-fringe
[magit]: http://magit.github.io/
[git-flow]: https://github.com/jtatarik/magit-gitflow
[smeargle]: https://github.com/syohex/emacs-smeargle
[git-timemachine]: https://github.com/pidu/git-timemachine
[git-messenger]: https://github.com/syohex/emacs-git-messenger

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

BIN
contrib/git/git.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

159
contrib/git/packages.el Normal file
View File

@ -0,0 +1,159 @@
(defvar git-packages
'(
git-gutter-fringe
git-messenger
git-timemachine
magit
magit-gitflow
smeargle
)
"List of all packages to install and/or initialize. Built-in packages
which require an initialization must be listed explicitly in the list.")
(defun git/init-git-gutter-fringe ()
(use-package git-gutter-fringe
:commands git-gutter-mode
:init
(add-to-hooks 'git-gutter-mode '(markdown-mode-hook
org-mode-hook
prog-mode-hook
))
:config
(progn
(setq git-gutter:hide-gutter t)
;; Don't need log/message.
(setq git-gutter:verbosity 0)
(setq git-gutter-fr:side 'right-fringe)
;; (setq git-gutter:update-hooks '(after-save-hook after-revert-hook))
;; custom graphics that works nice with half-width fringes
(fringe-helper-define 'git-gutter-fr:added nil
"..X...."
"..X...."
"XXXXX.."
"..X...."
"..X...."
)
(fringe-helper-define 'git-gutter-fr:deleted nil
"......."
"......."
"XXXXX.."
"......."
"......."
)
(fringe-helper-define 'git-gutter-fr:modified nil
"..X...."
".XXX..."
"XXXXX.."
".XXX..."
"..X...."
)
(spacemacs|hide-lighter git-gutter-mode))))
(defun git/init-git-messenger ()
(use-package git-messenger
:defer t
:init
(evil-leader/set-key
"gm" 'git-messenger:popup-message)))
(defun git/init-git-timemachine ()
(use-package git-timemachine
:defer t
:init
(evil-leader/set-key
"gt" 'git-timemachine)))
(defun git/init-magit ()
(use-package magit
:defer t
:init
(evil-leader/set-key "gs" 'magit-status)
:config
(progn
(spacemacs|hide-lighter magit-auto-revert-mode)
;; full screen magit-status
(defadvice magit-status (around magit-fullscreen activate)
(window-configuration-to-register :magit-fullscreen)
ad-do-it
(delete-other-windows))
;; hjkl key bindings
(spacemacs|evilify magit-commit-mode-map
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-log-mode-map
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-process-mode-map
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-branch-manager-mode-map
"K" 'magit-discard-item
"L" 'magit-key-mode-popup-logging
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-status-mode-map
"K" 'magit-discard-item
"L" 'magit-key-mode-popup-logging
"H" 'magit-key-mode-popup-diff-options
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
;; remove conflicts with evil leader
(spacemacs/activate-evil-leader-for-maps '(magit-mode-map
magit-commit-mode-map
magit-diff-mode-map))
(defun magit-quit-session ()
"Restores the previous window configuration and kills the magit buffer"
(interactive)
(kill-buffer)
(jump-to-register :magit-fullscreen))
(define-key magit-status-mode-map (kbd "q") 'magit-quit-session)
(defun magit-toggle-whitespace ()
(interactive)
(if (member "-w" magit-diff-options)
(magit-dont-ignore-whitespace)
(magit-ignore-whitespace)))
(defun magit-ignore-whitespace ()
(interactive)
(add-to-list 'magit-diff-options "-w")
(magit-refresh))
(defun magit-dont-ignore-whitespace ()
(interactive)
(setq magit-diff-options (remove "-w" magit-diff-options))
(magit-refresh))
(define-key magit-status-mode-map (kbd "W") 'magit-toggle-whitespace))))
(defun git/init-magit-gitflow ()
(use-package magit-gitflow
:commands turn-on-magit-gitflow
:init (add-hook 'magit-mode-hook 'turn-on-magit-gitflow)
:config (spacemacs|diminish magit-gitflow-mode "Flow")))
(defun git/init-smeargle ()
(use-package smeargle
:defer t
:init
(evil-leader/set-key
"gcC" 'smeargle-clear
"gcc" 'smeargle-commits
"gct" 'smeargle)))

View File

@ -639,7 +639,7 @@ customization which make it unique compared to other kits:
- unicode symbols for minor mode lighters which appear in the mode-line
- [custom fringe bitmaps](#errors-handling) and error feedbacks for
[Flycheck][flycheck]
- [custom fringe bitmaps](#git-gutter-bitmaps) for [git gutter][git-gutter]
- [custom fringe bitmaps](../contrib/git/README.md#git-gutter-bitmaps) for [git gutter][]
- dedicated startup page with a mode aimed at easily managing `Spacemacs`
## Toggles
@ -1576,118 +1576,6 @@ To search in a project see [project searching](#project-searching).
<kbd>SPC p T</kbd> | find test files
<kbd>SPC p v</kbd> | open project root in `vc-dir` or `magit`
## Working with Git
Git commands (start with `g`):
Key Binding | Description
---------------------------|------------------------------------------------------------
<kbd>SPC g c c</kbd> | highlight regions by age of commits
<kbd>SPC g c C</kbd> | clear highlights
<kbd>SPC g c t</kbd> | highlight regions by last updated time
<kbd>SPC g s</kbd> | open a `magit` status window
<kbd>SPC g m</kbd> | display the last commit message of the current line
<kbd>SPC g t</kbd> | launch the git time machine
- Highlight by age of commit or last update time is provided by
[smeargle][smeargle].
- Git time machine is provided by [git-timemachine][git-timemachine].
- Git last commit message per line is provided by
[git-messenger][git-messenger]
### Magit
`Spacemacs` uses [magit][magit] to manage Git repositories.
To open a `status buffer`, type in a buffer of a Git repository:
<SPC> g s
`hjkl` navigation is enabled in all Magit buffers. The default Magit keys
on `hjkl` are remapped on `HJKL`.
Here are the often used bindings inside a `status buffer`:
Key Binding | Description
------------------|------------------------------------------------------------
<kbd>/</kbd> | evil-search
<kbd>$</kbd> | open `command output buffer`
<kbd>c c</kbd> | open a `commit message buffer`
<kbd>b b</kbd> | checkout a branch
<kbd>b c</kbd> | create a branch
<kbd>b v</kbd> | open the `branch manager buffer`
<kbd>f f</kbd> | fetch changes
<kbd>F -r F</kbd> | pull and rebase
<kbd>h</kbd> | go left
<kbd>j</kbd> | go down
<kbd>C-j</kbd | goto next magit section
<kbd>k</kbd> | go up
<kbd>K</kbd> | discard changes
<kbd>C-k</kbd | goto previous magit section
<kbd>l</kbd> | go right
<kbd>L l</kbd> | open `log buffer`
<kbd>n</kbd> | next search occurrence
<kbd>C-n</kbd | goto next magit section
<kbd>N</kbd> | previous search occurrence
<kbd>P P</kbd> | push
<kbd>C-p</kbd | goto previous magit section
<kbd>q</kbd> | quit
<kbd>s</kbd> | on a file or hunk in a diff: stage the file or hunk
<kbd>+</kbd> | on a hunk: increase hunk size
<kbd>-</kbd> | on a hunk: decrease hunk size
<kbd>S</kbd> | stage all
<kbd>TAB</kbd> | on a file: expand/collapse diff
<kbd>u</kbd> | on a staged file: unstage
<kbd>U</kbd> | unstage all staged files
<kbd>v</kbd> | `visual state`
<kbd>V</kbd> | `visual-line state`
<kbd>C-v</kbd> | revert item at point
<kbd>z z</kbd> | stash changes
In a commit message buffer press `C-c C-c` to commit the changes with the
entered message. `C-c C-k` will discard the commit message.
**Note:** Sometimes you will be asked about reverting the commit buffer,
you can answer `y` with no issue.
### Quick guide for recurring use cases in Magit
- Amend a commit:
- `L l` to open `log buffer`
- `c a` on the commit you want to amend
- `C-c C-c` to submit the changes
- Squash last commit:
- `L l` to open `log buffer`
- `E` on the second to last commit, it opens the `rebase buffer`
- `j` to put point on last commit
- `i` to pass in `insert state`
- `s` to squash it
- `C-c C-c` to continue to the `commit message buffer`
- `C-c C-c` again when you have finished to edit the commit message
- Force push a squashed commit:
- in the `status buffer` you should see the new commit unpushed and the
old commit unpulled
- `P -f P` for force a push (**beware** usually it is not recommended to
rewrite the history of a public repository, but if you are *sure* that you
are the only one to work on a repository it is ok - i.e. in your fork).
- Add upstream remote (the parent repository you have forked):
- `b v` to open the `branch manager buffer`
- `a` to add a remote, type the name (i.e. `upstream`) and the URL
- Pull changes from upstream (the parent repository you have forked) and push:
- `F -r C-u F` and choose `upstream` or the name you gave to it
- `P P` to push the commit to `origin`
### Git gutter bitmaps
`Spacemacs` has custom fringe bitmaps for
[git-gutter-fringe][git-gutter]:
Symbol | Description
:-------------------------------------------------------------------------------------------:|-----------------
![git-new](img/git-new-line.png) | new line
![git-del](img/git-del-line.png) | at least one line has been deleted
![git-mod](img/git-mod-line.png) | modified line
## Registers
Access commands to the various registers start with `r`:
@ -2027,6 +1915,7 @@ developers to elisp hackers!
[evil-numbers]: https://github.com/cofi/evil-numbers
[evil-org-mode]: https://github.com/edwtjo/evil-org-mode
[evil-lisp-state]: https://github.com/syl20bnr/evil-lisp-state
[git-gutter]: https://github.com/syohex/emacs-git-gutter-fringe
[nose]: https://github.com/nose-devs/nose/
[nose.el]: https://github.com/syl20bnr/nose.el
[pylookup]: https://github.com/tsgates/pylookup
@ -2036,11 +1925,6 @@ developers to elisp hackers!
[leuven-theme]: https://github.com/fniessen/emacs-leuven-theme
[monokai-theme]: https://github.com/oneKelvinSmith/monokai-emacs
[zenburn-theme]: https://github.com/bbatsov/zenburn-emacs
[git-gutter]: https://github.com/syohex/emacs-git-gutter-fringe
[magit]: http://magit.github.io/
[smeargle]: https://github.com/syohex/emacs-smeargle
[git-timemachine]: https://github.com/pidu/git-timemachine
[git-messenger]: https://github.com/syohex/emacs-git-messenger
[ido-vertical-mode]: https://github.com/gempesaw/ido-vertical-mode.el
[issues]: https://github.com/syl20bnr/spacemacs/issues
[vundle]: https://github.com/gmarik/Vundle.vim

View File

@ -38,10 +38,6 @@
flycheck
flycheck-ledger
flyspell
fringe-helper
git-gutter-fringe
git-messenger
git-timemachine
golden-ratio
google-translate
guide-key-tip
@ -67,8 +63,6 @@
leuven-theme
linum-relative
key-chord
magit
magit-gitflow
markdown-mode
markdown-toc
monokai-theme
@ -103,7 +97,6 @@
scss-mode
shell
smartparens
smeargle
smooth-scrolling
string-edit
subword
@ -936,59 +929,6 @@ determine the state to enable when escaping from the insert state.")
:config
(spacemacs|diminish flyspell-mode "")))
(defun spacemacs/init-git-gutter-fringe ()
(use-package git-gutter-fringe
:commands git-gutter-mode
:init
(add-to-hooks 'git-gutter-mode '(markdown-mode-hook
org-mode-hook
prog-mode-hook
))
:config
(progn
(setq git-gutter:hide-gutter t)
;; Don't need log/message.
(setq git-gutter:verbosity 0)
(setq git-gutter-fr:side 'right-fringe)
;; (setq git-gutter:update-hooks '(after-save-hook after-revert-hook))
;; custom graphics that works nice with half-width fringes
(fringe-helper-define 'git-gutter-fr:added nil
"..X...."
"..X...."
"XXXXX.."
"..X...."
"..X...."
)
(fringe-helper-define 'git-gutter-fr:deleted nil
"......."
"......."
"XXXXX.."
"......."
"......."
)
(fringe-helper-define 'git-gutter-fr:modified nil
"..X...."
".XXX..."
"XXXXX.."
".XXX..."
"..X...."
)
(spacemacs|hide-lighter git-gutter-mode))))
(defun spacemacs/init-git-messenger ()
(use-package git-messenger
:defer t
:init
(evil-leader/set-key
"gm" 'git-messenger:popup-message)))
(defun spacemacs/init-git-timemachine ()
(use-package git-timemachine
:defer t
:init
(evil-leader/set-key
"gt" 'git-timemachine)))
(defun spacemacs/init-golden-ratio ()
(use-package golden-ratio
:defer t
@ -1346,92 +1286,6 @@ determine the state to enable when escaping from the insert state.")
(setq linum-relative-current-symbol "")
(linum-relative-toggle))))
(defun spacemacs/init-magit ()
(use-package magit
:defer t
:init
(evil-leader/set-key "gs" 'magit-status)
:config
(progn
(spacemacs|hide-lighter magit-auto-revert-mode)
;; full screen magit-status
(defadvice magit-status (around magit-fullscreen activate)
(window-configuration-to-register :magit-fullscreen)
ad-do-it
(delete-other-windows))
;; hjkl key bindings
(spacemacs|evilify magit-commit-mode-map
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-log-mode-map
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-process-mode-map
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-branch-manager-mode-map
"K" 'magit-discard-item
"L" 'magit-key-mode-popup-logging
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
(spacemacs|evilify magit-status-mode-map
"K" 'magit-discard-item
"L" 'magit-key-mode-popup-logging
"H" 'magit-key-mode-popup-diff-options
(kbd "C-j") 'magit-goto-next-section
(kbd "C-k") 'magit-goto-previous-section
(kbd "C-n") 'magit-goto-next-section
(kbd "C-p") 'magit-goto-previous-section
(kbd "C-v") 'magit-revert-item)
;; remove conflicts with evil leader
(spacemacs/activate-evil-leader-for-maps '(magit-mode-map
magit-commit-mode-map
magit-diff-mode-map))
(defun magit-quit-session ()
"Restores the previous window configuration and kills the magit buffer"
(interactive)
(kill-buffer)
(jump-to-register :magit-fullscreen))
(define-key magit-status-mode-map (kbd "q") 'magit-quit-session)
(defun magit-toggle-whitespace ()
(interactive)
(if (member "-w" magit-diff-options)
(magit-dont-ignore-whitespace)
(magit-ignore-whitespace)))
(defun magit-ignore-whitespace ()
(interactive)
(add-to-list 'magit-diff-options "-w")
(magit-refresh))
(defun magit-dont-ignore-whitespace ()
(interactive)
(setq magit-diff-options (remove "-w" magit-diff-options))
(magit-refresh))
(define-key magit-status-mode-map (kbd "W") 'magit-toggle-whitespace))))
(defun spacemacs/init-magit-gitflow ()
(use-package magit-gitflow
:commands turn-on-magit-gitflow
:init (add-hook 'magit-mode-hook 'turn-on-magit-gitflow)
:config (spacemacs|diminish magit-gitflow-mode "Flow")))
(defun spacemacs/init-markdown-mode ()
(use-package markdown-mode
:mode ("\\.md" . markdown-mode)
@ -1978,15 +1832,6 @@ determine the state to enable when escaping from the insert state.")
(sp-pair "[" nil :post-handlers
'(:add (spacemacs/smartparens-pair-newline-and-indent "RET"))))))
(defun spacemacs/init-smeargle ()
(use-package smeargle
:defer t
:init
(evil-leader/set-key
"gcC" 'smeargle-clear
"gcc" 'smeargle-commits
"gct" 'smeargle)))
(defun spacemacs/init-smooth-scrolling ()
;; this is not a conventional package