Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
* next:
  Update Changelog
  plugin/magit.vim: move s:magit_commit_mode to buffer variable b:magit_current_commit_mode
  plugin/magit.vim: move s:state to buffer variable b:state
  plugin/magit.vim: display commit mode in Info section
  syntax/magit.vim: rework section title color
  Update Changelog
  README,doc: add notes that magit handles multiple git repo
  README,doc: misc changes
  plugin/magit.vim: add mappings N and P to jump to next and previous hunk (fix #25)
  syntax/magit.vim: add some color in Info section
  plugin/magit.vim: disable inline help by default (fix #46)
  plugin/magit.vim: update inline help
  state.vim: display modified files first
  plugin/magit.vim: in show_magit(), always open buffer with :buffer command (fix #41)
  plugin/magit.vim,autoload/git.vim: yet another rework of magit#show_magit() (fix #41)
  plugin/magit.vim,autoload/{git,sign}.vim: magit can handle multiple git repository within one vim session (fix #44,#34,#29)
  plugin/magit.vim: add MagitOnly command
  plugin/magit.vim: better handling of magit buffer, including clean quit command (fix #43)
  • Loading branch information
jreybert committed Nov 30, 2015
2 parents 9e084f7 + d1b6b4c commit 725817e
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 119 deletions.
117 changes: 111 additions & 6 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,16 +1,118 @@
Release 1.5.0
=============

Features
--------

* vimagit is now able to handle multiple git repositories (fix #44,#34,#29).
* add mappings N and P to jump to next and previous hunk (fix #25).
* reorder magit display: display modified files first.
* disable inline help by default (fix #46). It is always possible to switch
inline help display with 'h', or with g:magit_show_help
* rework magit buffer color syntax.
* display commit mode in Info section.
* rename magit buffer, now named after git repository path, e.g.
magit:///path/to/git/repo/
* add MagitOnly command. It can be used to craft a bash alias like:
alias magit='vim -c MagitOnly'

Fixes
-----

* safe and smart handling of quit command (fix #41,#43).
* close vimagit window if there is another window.
* switch to alternate buffer if any.
* close vim if magit buffer the only buffer.
* disable ':w' mapping, which was not safe. This feature will be re inserted
with a safer method later.

Release 1.4.2
=============

Enhancements
------------

* smarter way to handle magit buffer:
* improve some internal mechanisms, which should improve performances for
huge repositories
* by default, do not show untracked/deleted/added/renamed files diffs (ref
#28)
* see g:magit_default_show_all_files new behavior
* add g:magit_default_sections to let user choose which sections are displayed
(fix #37) user can now choose which sections to display, and in which order

Bug fixes
---------

* magit buffer become empty after switching to other window and back (#35)
* remove warning when opening magit buffer
* check that magit buffer exists before removing it (refs #39)

Release 1.4.1
=============

Fixes
-----

* fix add binary file (fixes #27)
* fix some display problem (Unstaged changes may not be highlighted)
* fix reset and discard for binary files

Features
--------

* git works in a clean environment, without any configuration

Release 1.4
===========

This is a major step for vimagit. It should now contain all primary command
needed for staging. Then, this release should be the real 1.0 version.

Features
--------

* Stage parts of hunk (fixes #8 and #19)
* select some with v, then stage your selection with S
* stage a single line with L
* mark lines (can be non contiguous) with M, then stage marked lines in
the hunk with S
* Stage single files in new directories (fixes #10)
* New options (fixes #18)
* g:magit_default_show_all_files to define if file diffs are shown or not
at magit buffer opening.
* If magit buffer contains more than g:magit_warning_max_lines (default
10000) lines to display, user is asked if he wants to display all
these lines.
* g:magit_default_fold_level to define foldlevel of magit buffer.
* These options can be overriden with new magit#show_magit() parameters
(allowing user to define its own mappings/commands)
* File display is now sorted.
* Show submodule diffs (fixes #12)

Fixes
-----

No bugs have been reported since release 1.3.

Release 1.3
===========

Features
--------

* hide file diffs: to hide/unhide diffs for a file, move the cursor to the filename and press <CR> (Enter). It allows vimagit to be fast when there is a lot of diffs in a repository.
* hide file diffs: to hide/unhide diffs for a file, move the cursor to the
filename and press <CR> (Enter). It allows vimagit to be fast when there is a
lot of diffs in a repository.
* zo, zO, zc, zC mappings on a filename hide/unhide file diffs.
* modify hunk before staging: in the Magit buffer, it is possible to modify a hunk before staging it. Only '+' lines can be modified. No lines can be deleted or added for the moment. (fixes #9).
* modify hunk before staging: in the Magit buffer, it is possible to modify a
hunk before staging it. Only '+' lines can be modified. No lines can be
deleted or added for the moment. (fixes #9).
* handle new empty files and new symlink (fix #11).
* handle binary files (fix #13).
* stage/unstage/ignore/discard a file with cursor on the filename.
* add global mapping <Leader>M to open magit buffer (it can be overwritten with g:magit_show_magit_mapping).
* add global mapping <Leader>M to open magit buffer (it can be overwritten
with g:magit_show_magit_mapping).
* remove 'C' default mapping.

Fixes
Expand All @@ -25,7 +127,8 @@ Release 1.2
Fixes
-----

* read COMMIT_EDITMSG only if exists (commit command failed for fresh new git directory)
* read COMMIT_EDITMSG only if exists (commit command failed for fresh new git
directory)
* fix issue of some rare hunk staging (because of some whitespaces)

Features
Expand All @@ -40,8 +143,10 @@ Release 1.1
Fixes
-----

* add wrappers to system and systemlist, when vim doesn't support system with List (available since vim v7.4.248)
* fix git diff failing when cwd is not in top dir (it ends with an empty Magit buffer)
* add wrappers to system and systemlist, when vim doesn't support system with
List (available since vim v7.4.248)
* fix git diff failing when cwd is not in top dir (it ends with an empty Magit
buffer)
* ensure to not use external diff if any
* Check commentChar from git config

Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Take a look at [TL;DR](#tldr) to start using it immediatly.
* [x] Stage part of hunks, by visual select, lines or selecting bunch of lines with marks.
* [x] Start to write the commit message in one key press, commit also in one key press.
* [x] Modify in line the content just before staging it.
* [x] Visualize stashes. Apply, pop, drop are on going.
* [x] Move easily through hunks.
* [x] Handle multiple git repositories within one vim instance.
* [x] Add file to .gitignore file.
* [ ] Chase all corner cases. Please remember that vimagit is at an early development stage. If you try vimagit and nothing is working, please don't throw it, fill an [issue](https://github.com/jreybert/vimagit/issues/new) on github :heart: !

Expand All @@ -34,6 +35,7 @@ More to come:
* Handle multiple git repositories within one vim session.
* Stage multiple hunks or file by visually selecting them.
* Go through history, cherry-pick changes.
* Handle stash: add, pop, apply, drop...
* Vizualize and checkout branches.
* Something is missing? Open an [issue](https://github.com/jreybert/vimagit/issues/new)!

Expand All @@ -60,12 +62,15 @@ This is the minimal required set of command you must know to start playing with

#### :Magit

Open magit buffer.
Open magit buffer (see [details](#magitshow_magit)).

#### Enter,\<CR\>

All files diffs are hidden by default. To inspect changes in a file, move cursor to the filename line, and press 'Enter' in Normal mode. Diffs are displayed below the file name.

#### N
* Jump to next hunk with **N**.

#### S

* Modify a file, for example foo.c, in your repository.
Expand Down Expand Up @@ -115,7 +120,9 @@ Visual selection and marked lines have some limitations for the moment:

#### magit#show_magit()

Function to open magit buffer.
Function to open magit buffer. This buffer will handle the git repository including focused file.
It is possible to handle multiple git repositories within one vim instance.

It takes 3 parameters:
* orientation (mandatory): it can be
- 'v', curent window is split vertically, and magit is displayed in new
Expand All @@ -129,7 +136,12 @@ It takes 3 parameters:
(see [g:magit_default_fold_level](#gmagit_default_fold_level))

#### :Magit
* open magit buffer.
Open magit buffer in a vertical split (see [details](magitshow_magit)).

#### :MagitOnly
Open magit buffer in current window (see [details](magitshow_magit)).

You can create a bash alias like magit="vim -c MagitOnly"

### Mappings

Expand Down Expand Up @@ -181,6 +193,9 @@ Following mappings are set locally, for magit buffer only, in normal mode.
* If cursor is in diff header, discard whole file at cursor position.
* Only works in "Unstaged changes" section.

##### N,P
* 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, commit the all staged changes in commit mode previously set.
Expand Down
74 changes: 50 additions & 24 deletions autoload/magit/git.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,65 @@ function! magit#git#get_status()
return file_list
endfunction

" s:magit_top_dir: top directory of git tree
" it is evaluated only once
" FIXME: it won't work when playing with multiple git directories wihtin one
" vim session
let s:magit_top_dir=''
" magit#git#top_dir: return the absolute path of current git worktree
" return top directory
function! magit#git#top_dir()
if ( s:magit_top_dir == '' )
let s:magit_top_dir=magit#utils#strip(
\ system(s:git_cmd . " rev-parse --show-toplevel")) . "/"
" magit#git#is_work_tree: this function check that path passed as parameter is
" inside a git work tree
" param[in] path: path to check
" return: top work tree path if in a work tree, empty string otherwise
function! magit#git#is_work_tree(path)
let dir = getcwd()
try
call magit#utils#lcd(a:path)
let top_dir=magit#utils#strip(
\ system(s:git_cmd . " rev-parse --show-toplevel")) . "/"
if ( v:shell_error != 0 )
return ''
endif
return top_dir
finally
call magit#utils#lcd(dir)
endtry
endfunction

" magit#git#set_top_dir: this function set b:magit_top_dir and b:magit_git_dir
" according to a path
" param[in] path: path to set. This path must be in a git repository work tree
function! magit#git#set_top_dir(path)
let dir = getcwd()
try
call magit#utils#lcd(a:path)
let top_dir=magit#utils#strip(
\ system(s:git_cmd . " rev-parse --show-toplevel")) . "/"
if ( v:shell_error != 0 )
throw "magit: git-show-toplevel error: " . top_dir
endif
let git_dir=magit#utils#strip(system(s:git_cmd . " rev-parse --git-dir")) . "/"
if ( v:shell_error != 0 )
echoerr "Git error: " . s:magit_top_dir
throw "magit: git-git-dir error: " . git_dir
endif
let b:magit_top_dir=top_dir
let b:magit_git_dir=git_dir
finally
call magit#utils#lcd(dir)
endtry
endfunction

" magit#git#top_dir: return the absolute path of current git worktree for the
" current magit buffer
" return top directory
function! magit#git#top_dir()
if ( !exists("b:magit_top_dir") )
throw 'top_dir_not_set'
endif
return s:magit_top_dir
return b:magit_top_dir
endfunction

" s:magit_git_dir: git directory
" it is evaluated only once
" FIXME: it won't work when playing with multiple git directories wihtin one
" vim session
let s:magit_git_dir=''
" magit#git#git_dir: return the absolute path of current git worktree
" return git directory
function! magit#git#git_dir()
if ( s:magit_git_dir == '' )
let s:magit_git_dir=magit#utils#strip(system(s:git_cmd . " rev-parse --git-dir")) . "/"
if ( v:shell_error != 0 )
echoerr "Git error: " . s:magit_git_dir
endif
if ( !exists("b:magit_git_dir") )
throw 'git_dir_not_set'
endif
return s:magit_git_dir
return b:magit_git_dir
endfunction

" magit#git#git_diff: helper function to get diff of a file
Expand Down
2 changes: 0 additions & 2 deletions autoload/magit/sign.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ let s:dummy_sign_id = s:first_sign_id - 1
" Remove-all-signs optimisation requires Vim 7.3.596+.
let s:supports_star = v:version > 703 || (v:version == 703 && has("patch596"))

let s:bufnr = bufnr(g:magit_buffer_name)

function! magit#sign#remove_all(...)
if ( a:0 == 1 )
let pattern = a:1
Expand Down
23 changes: 21 additions & 2 deletions autoload/magit/state.vim
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,31 @@ function! magit#state#set_files_visible(is_visible) dict
endfor
endfunction

" magit#state#get_files: global dict getter function
" magit#state#get_files: global dict file objects getter function
" param[in] mode: mode to select, can be 'staged' or 'unstaged'
" return all files belonging to mode
" return list of file objects belonging to mode
function! magit#state#get_files(mode) dict
return self.dict[a:mode]
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 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)
else
call add(others, filename)
endif
endfor
return modified + others
endfunction


" dict: structure containing all diffs
" It is formatted as follow
Expand All @@ -330,6 +348,7 @@ let magit#state#state = {
\ 'nb_diff_lines': 0,
\ 'get_file': function("magit#state#get_file"),
\ 'get_files': function("magit#state#get_files"),
\ 'get_filenames': function("magit#state#get_filenames"),
\ 'add_file': function("magit#state#add_file"),
\ 'set_files_visible': function("magit#state#set_files_visible"),
\ 'check_max_lines': function("magit#state#check_max_lines"),
Expand Down
12 changes: 12 additions & 0 deletions common/magit_common.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ let g:magit_sections = {
\ 'stash': 'Stash list'
\ }

let g:magit_section_info = {
\ 'cur_repo': 'Current repository',
\ 'cur_branch': 'Current branch',
\ 'cur_commit': 'Last commit',
\ 'commit_mode': 'Commit mode',
\ }

let g:magit_git_status_code = {
\ 'M': 'modified',
\ 'A': 'added',
Expand All @@ -25,6 +32,11 @@ let g:magit_git_status_code = {
\ 'S': 'submodule',
\ }

let g:magit_commit_mode = {
\ 'CC': 'normal',
\ 'CA': 'amend',
\ }

" Regular expressions used to select blocks
let g:magit_file_re = '^\('
for status_code in values(g:magit_git_status_code)
Expand Down
Loading

0 comments on commit 725817e

Please sign in to comment.