Skip to content

Commit

Permalink
Merge branch 'next' of https://github.com/jreybert/vimagit
Browse files Browse the repository at this point in the history
* 'next' of https://github.com/jreybert/vimagit:
  fix smart magit close behavior
  plugin/magit.vim: if opened with MagitOnly, 'q' shows previous buffer
  test: fix gold file after previous commit
  plugin/magit.vim: fix template commit duplicate on refresh
  plugin/magit.vim: fix warning when magit is closed with bdelete
  smart cursor position when no previous file
  doc: introduce vimagit modes
  update commit mode to amend if already in commit mode
  README: fix <C-n> in markdown
  Fix jump to "file already aopen" abort
  syntax/magit.vim: fix sha1 highlight
  test/version.vader: fix test description
  plugin/magit.vim: update version to 1.7.1
  Open magit buffer with a smart cursor position
  fix: make gaps between sections consistent
  plugin/magit.vim: <cr> toggle vim folding (ref #71)
  • Loading branch information
jreybert committed Aug 1, 2017
2 parents e233441 + 4a3fa83 commit 3f0c0ef
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 50 deletions.
39 changes: 32 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,38 @@ This plugin follows the standard runtime path structure, and as such it can be i

## Usage

### Modes

vimagit buffer has modes. Mappings may have different behavior, depending on current mode and curosr position.

For the moment, vimagit counts only two modes.

#### Stage mode

This is the default mode. In this mode, you can stage and unstage hunks, refresh vimagit buffer...

#### Commit mode

In this mode, "Commit message" section is open, you can write your commit message and validate your commit.

Commit mode has two flavors.

##### Commit mode flavors

* *Normal*: current commit will be a new commit.
* *Amend*: current commit will be meld with previous commit.
* Previous commit message is shown in "Commit message" section.
* Use this flavor if you forgot something in the previous commit.

By the way, you can also perform all [stage mode](stage_mode) actions in [commit mode](commit_mode).

### Sections

IMPORTANT: mappings can have different meanings regarding the cursor position.

There are 5 sections:
* Info: this section display some information about the git repository, like the current branch and the HEAD commit.
* Commit message: this section appears in commit mode (see below). It contains the message to be committed.
* Commit message: this section appears in [commit mode](commit_mode). It contains the message to be committed.
* Staged changes: this sections contains all staged files/hunks, ready to commit.
* Unstaged changes: this section contains all unstaged and untracked files/hunks.
* Stash list: this section contains all stahes.
Expand Down Expand Up @@ -208,20 +233,20 @@ E means 'edit'.
* Move to **N**ext or **P**revious hunk.

##### CC
* If not in commit section, set commit mode to "New commit" and show "Commit message" section with brand new commit message.
* If in commit section, create the commit with the commit message and all staged changes.
* From [stage mode](stage_mode), set [commit mode](commit_mode) in [normal flavor](commit_mode_flavors) and show empty "Commit message" section.
* From [commit mode](commit_mode), commit all staged changes with [commit flavor](commit_mode_flavors) (*normal* or *amend*) with message in "Commit message" section.

##### :w :x :wq ZZ
* If in commit section, create the commit with the commit message and all staged changes.
* From [commit mode](commit_mode), commit all staged changes with [commit flavor](commit_mode_flavors) (*normal* or *amend*) with message in "Commit message" section.

##### CA
* If not in commit section, set commit mode to "Amend commit" and show "Commit message" section with previous commit message.
* From [stage mode](stage_mode) or [commit mode](commit_mode): set [commit mode](commit_mode) in [amend flavor](commit_mode_flavors), and display "Commit message" section with previous commit message. Commit will be meld with previous commit.

##### CF
* Amend the staged changes into the previous commit, without modifying previous commit message.
* From [stage mode](stage_mode): amend the staged changes into the previous commit, without modifying previous commit message.

##### CU
* Close a commit section (If you need soon after open or editing commit message, pressing 'u' is good enough).
* From [commit mode](commit_mode): go back to stage mode (current commit message will be lost).

##### I
* Add the file under the cursor in .gitgnore
Expand Down
14 changes: 7 additions & 7 deletions autoload/magit/mapping.vim
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ function! magit#mapping#set_default()
\g:magit_folding_toggle_mapping[0]
\. ' if cursor on filename header line, unhide diffs for this file',
\g:magit_commit_mapping
\. ' set commit mode to normal, and show "Commit message" section',
\' In commit mode, commit all staged changes with commit mode previously',
\' set (normal or amend) with message written in this section',
\. ' From stage mode: set commit mode in normal flavor',
\' From commit mode: commit all staged changes with commit flavor',
\' (normal or amend) with message in "Commit message" section',
\g:magit_commit_amend_mapping
\. ' set commit mode amend, and show "Commit message" section with previous',
\' commit message',
\. ' From stage or commit mode: set commit mode in amend flavor, and',
\' display "Commit message" section with previous commit message.',
\g:magit_commit_fixup_mapping
\. ' amend staged changes to previous commit without modifying the previous',
\' commit message',
\. ' From stage mode: amend staged changes to previous commit without',
\' modifying the previous commit message',
\g:magit_close_commit_mapping
\. ' commit undo, cancel and close current commit message',
\g:magit_reload_mapping
Expand Down
21 changes: 15 additions & 6 deletions autoload/magit/state.vim
Original file line number Diff line number Diff line change
Expand Up @@ -321,24 +321,32 @@ function! magit#state#get_files(mode) dict
return self.dict[a:mode]
endfunction

" magit#state#get_filenames: global dict filenames getter function
" magit#state#get_files: global dict file objects (copy) getter function
" param[in] mode: mode to select, can be 'staged' or 'unstaged'
" return ordered list of filename strings belonging to mode, modified files
" first
function! magit#state#get_filenames(mode) dict
" return ordered list of file objects belonging to mode
function! magit#state#get_files_ordered(mode) dict
let modified = []
let others = []
for filename in sort(keys(self.dict[a:mode]))
let file = self.get_file(a:mode, filename)
if ( file.status == 'M' )
call add(modified, filename)
call add(modified, file)
else
call add(others, filename)
call add(others, file)
endif
endfor
return modified + others
endfunction

" magit#state#get_filenames: global dict filenames getter function
" param[in] mode: mode to select, can be 'staged' or 'unstaged'
" return ordered list of filename strings belonging to mode, modified files
" first
function! magit#state#get_filenames(mode) dict
let files = self.get_files_ordered(a:mode)
return map(copy(files), 'v:val.filename')
endfunction


" dict: structure containing all diffs
" It is formatted as follow
Expand All @@ -358,6 +366,7 @@ let magit#state#state = {
\ 'nb_diff_lines': 0,
\ 'get_file': function("magit#state#get_file"),
\ 'get_files': function("magit#state#get_files"),
\ 'get_files_ordered': function("magit#state#get_files_ordered"),
\ 'get_filenames': function("magit#state#get_filenames"),
\ 'add_file': function("magit#state#add_file"),
\ 'set_files_visible': function("magit#state#set_files_visible"),
Expand Down
60 changes: 43 additions & 17 deletions doc/vimagit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,41 @@ If you move the cursor to the file header and press S, the whole file is
staged.

> CC
Once you have stage all the required changes, type CC. A new section "Commit
message" appears and cursor move to it. Type your commit message, in Insert mode
this time. Once it's done, write your commit message with :w (or :x, :wq, ZZ).
Once you have stage all the required changes, type CC. A new section
`Commit message` appears and cursor move to it. Type your commit message, in
Insert mode this time. Once it's done, write your commit message with :w (or
:x, :wq, ZZ).

Voila! you created your first commit with vimagit!

===============================================================================
4. USAGE *vimagit-usage*

MODES *vimagit-modes*

vimagit buffer has modes. Mappings may have different behavior, depending on
current mode and curosr position.

For the moment, vimagit counts only two modes.

STAGE MODE *vimagit-stage-mode*

This is the default mode. In this mode, you can stage and unstage hunks,
refresh vimagit buffer...

COMMIT MODE *vimagit-commit-mode*

In this mode, `Commit message` section is open, you can write your commit
message and validate your commit.
Commit mode has two flavors.

* `normal`: current commit will be a new commit.
* `amend`: current commit will be meld with previous commit.
* Previous commit message is shown in `Commit message` section.
* Use this flavor if you forgot something in the previous commit.

By the way, you can also perform all stage mode actions in commit mode.

SECTIONS *vimagit-sections*

IMPORTANT: mappings can have different meanings regarding the cursor position.
Expand Down Expand Up @@ -241,32 +267,32 @@ Following mappings are set locally, for magit buffer only, in normal mode.

*vimagit-CC* *magit#commit_command('CC')*
*vimagit-g:magit_commit_mapping*
CC If not in commit section, set commit mode to "New commit" and show
"Commit message" section with brand new commit message.
If in commit section, create the commit with the commit message and
all staged changes.
CC From `stage mode`, set commit mode in `normal` flavor and show empty
"Commit message" section.
From `commit mode`, commit all staged changes with commit flavor
(`normal` or `amend`) with message in "Commit message" section.

*vimagit-:w*
:w :x :wq ZZ
If in commit section, create the commit with the commit message and
all staged changes.
From `commit mode`, commit all staged changes with commit flavor
(`normal` or `amend`) with message in "Commit message" section.

*vimagit-CA* *magit#commit_command('CA')*
*vimagit-g:magit_commit_amend_mapping*
CA If not in commit section, set commit mode to "Amend commit" and
show "Commit message" section with previous commit message.
If in commit section, commit the staged changes in commit mode
previously set.
CA From `stage mode` or `commit mode`: set commit mode in amend
flavor, and display "Commit message" section with previous commit
message.
Commit will be meld with previous commit.

*vimagit-CF* *magit#commit_command('CF')*
*vimagit-g:magit_commit_fixup_mapping*
CF Amend the staged changes into the previous commit, without
modifying previous commit message
CF From `stage mode`: amend the staged changes into the previous
commit, without modifying previous commit message.

*vimagit-CU* *magit#close_commit()*
*vimagit-g:magit_close_commit_mapping*
CU Close a commit section (If you need soon after open or editing
Ucommit message, pressing 'u' is good enough).
CU From `commit mode`: go back to stage mode (current commit message
will be lost).

*vimagit-I* *magit#ignore_file()*
*vimagit-g:magit_ignore_mapping*
Expand Down
Loading

0 comments on commit 3f0c0ef

Please sign in to comment.