From 6dc5e3a3a6c6cc2c5817af68d4f2934cdd5287b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Guth?= Date: Fri, 12 Apr 2019 11:42:04 +0200 Subject: [PATCH 1/5] Prevent git diff from using external tools with porcelain (#15) Fixes #14 --- autoload/lightline/gitdiff.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/lightline/gitdiff.vim b/autoload/lightline/gitdiff.vim index 1e084d9..3bd1725 100644 --- a/autoload/lightline/gitdiff.vim +++ b/autoload/lightline/gitdiff.vim @@ -131,7 +131,7 @@ endfunction function! s:get_diff_porcelain() abort " return the ouput of `git diff --word-diff=porcelain --unified=0` linewise " - let l:porcelain = systemlist('cd ' . expand('%:p:h:S') . ' && git diff --word-diff=porcelain --unified=0 -- ' . expand('%:t:S')) + let l:porcelain = systemlist('cd ' . expand('%:p:h:S') . ' && git diff --no-ext-diff --word-diff=porcelain --unified=0 -- ' . expand('%:t:S')) return l:porcelain[4:] endfunction From ff0b35e6f813e042c77b7e9a3b97ce954b4a5fba Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Sun, 21 Apr 2019 12:37:03 +0200 Subject: [PATCH 2/5] doc: include instructions on all (planned) public API features These include - changing the algorithm - adding a custom callback for `#update()` - usage with vim's vanilla `statusline` Closes #2 Closes #4 --- README.md | 97 ++++++++++++++++++++++++++-------- autoload/lightline/gitdiff.vim | 11 ++-- 2 files changed, 83 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f452d9e..16abbba 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,54 @@ # lightline-gitdiff -I had been using [airblade/vim-gitgutter][gitgutter] for a long time, however, -I felt distracted by the indicators in the sign column in the end. -Nevertheless, I wanted some lightweight signal telling me whether the current -file contains uncommitted changes or not. +I had been using [airblade/vim-gitgutter][gitgutter] for a while, however, I +felt distracted by the indicators shown in the sign column in the end. That +said, I wanted some lightweight signal indicating whether the current file +contains uncommitted changes to the repository or not. -So, this little plugin for [itchyny/lightline.vim][lightline] was born. By -default the plugin shows an indicator such as the following: +So, this little plugin was born. I myself use +[itchyny/lightline.vim][lightline] to configure the statusline of vim easily, +so this is where the name of the plugin comes from. In addition, I embrace +lightlines's philosophy to provide a lightweight and stable, yet configurable +plugin that "just works". However, you can also integrate the plugin with vim's +vanilla `statusline`. + +By default the plugin shows indicators such as the following: ``` -A: 4 D: 6 +A: 4 D: 6 M: 2 ``` -This says that there are uncommitted changes. In the current buffer 4 lines -were added and 6 lines were deleted. If there are no uncommitted changes, -nothing is shown to reduce distraction. +This says that, in comparison to the git index, the current buffer contains 12 +uncommitted changes: four lines were deleted, six lines were added and two +lines only modified. If there are no uncommitted changes, nothing is shown to +reduce distraction. -A similar example is shown in the following screenshot. The first box indicates -where two files were added, the second box where a line was removed and the -third box shows the plugin in action: 2 lines added and 1 line removed. +You can see the plugin in action in my statusline/lightline: ![screenshot](https://raw.githubusercontent.com/wiki/niklaas/lightline-gitdiff/images/screenshot.png) -# Installation +## Installation + +Use your favorite plugin manager to install the plugin. I personally prefer +vim-plug but feel free to choose another one: + +```vim +Plug 'niklaas/lightline-gitdiff' +``` + +## Configuration + +### Using vim's vanilla statusline + +```vim +set statusline=%!lightline#gitdiff#get() +``` + +which let's your `statusline` consist of `gitdiff`'s indicators only. (Probably +not what you want but you can consult `:h statusline` for further information +on how to include additional elements.) -Use your favourite plugin manager and add `lightline#gitdiff#get` to your -lightline e.g.: +### Using lightline ```vim let g:lightline = { @@ -51,10 +74,12 @@ let g:lightline = { \ } ``` +which should give you pretty much the same result as shown in the screenshot. + # Configuration -You can configure the indicators and the separator between added and deleted -lines of code. The following are the defaults: +You can configure the appearance of the indicators and the separator between +them. The following are the defaults: ```vim let g:lightline#gitdiff#indicator_added = 'A: ' @@ -62,17 +87,47 @@ let g:lightline#gitdiff#indicator_deleted = 'D: ' let g:lightline#gitdiff#separator = ' ' ``` +A callback function is called every time the `diff` is updated and written to +the cache. By default this is `lightline#update()` to update lightline with +the newly calculated `diff`. However, you can also provide you own callback +function in the following way: + +```vim +let g:lightline#gitdiff#update_callback = { -> MyCustomCallback() } +``` + +If the callback function is not defined, the error is caught. This allows to +use the plugin with any type of `statusline` plugin. + +You can even change the algorithm that is used to calculate the `diff`. The +plugin comes bundled with two algorithms: `numstat` and `word_diff_porcelain`. +By default, the latter one is used because it allows to display modified lines. +`numstat` is much simpler but only supports showing added and deleted lines. +This resembles the default: + +```vim +let g:lightline#gitdiff#algorithm = + \ { -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate() } +``` + +Substitute `word_diff_porcelain` with `numstat` if you want to switch -- or +provide your own. Take a look at the source of both functions for inspiration +or consult me if you need help. I am happy to bundle additional faster and more +feature-rich algorithms in the package. + # How it works / performance -In the background, the plugin calls `git --numstat` for the current buffer and -caches the result. +In the background, `lightline#gitdiff#get()` calls `git --numstat` or `git +--word-diff=porcelain` (depending on the algorithm you choose, the latter being +the default) for the current buffer and caches the result. If possible e.g., when an already open buffer is entered, the cache is used and no call to `git` is made. `git` is only executed when reading or writing to a buffer. See the `augroup` in [plugin/lightline/gitdiff.vim][augroup]. If you have any suggestions to improve the performance, please let me know. I -am happy to implement them on my own -- or you can create a pull request. +am happy to implement your suggestions on my own -- or you can create a pull +request. # Bugs etc. diff --git a/autoload/lightline/gitdiff.vim b/autoload/lightline/gitdiff.vim index 98b9f6f..7aee671 100644 --- a/autoload/lightline/gitdiff.vim +++ b/autoload/lightline/gitdiff.vim @@ -10,15 +10,18 @@ endfunction " Lightline [1] originally. However, /there is no need to use Lightline/. " Since a callback is provided, you can update any other statusbar et al. " +" If the provided callback cannot be found, the error is caught. +" " [1]: https://github.com/itchyny/lightline.vim function! lightline#gitdiff#update(soft) call lightline#gitdiff#write_calculation_to_cache(a:soft) - let l:callback = get(g:, 'lightline#gitdiff#update_callback', 'lightline#update') + let l:Callback = get(g:, 'lightline#gitdiff#update_callback', { -> lightline#update() }) - if exists('*' . l:callback) - execute 'call ' . l:callback . '()' - endif + try + call l:Callback() + catch /^Vim\%((\a\+)\)\=:E117/ + endtry endfunction " write_calculation_to_cache() {{{1 writes the information got from an From 287ffdd019948ebeae88be783e3d7e37aecb3cc9 Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Sat, 25 May 2019 08:22:53 +0200 Subject: [PATCH 3/5] feat: update cache after commit was made Refs #9 --- autoload/lightline/gitdiff.vim | 14 ++++++++------ .../gitdiff/algorithms/word_diff_porcelain.vim | 16 ++++++++-------- autoload/lightline/gitdiff/utils.vim | 4 ++-- plugin/lightline/gitdiff.vim | 6 ++++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/autoload/lightline/gitdiff.vim b/autoload/lightline/gitdiff.vim index 7aee671..a8ae45b 100644 --- a/autoload/lightline/gitdiff.vim +++ b/autoload/lightline/gitdiff.vim @@ -13,8 +13,10 @@ endfunction " If the provided callback cannot be found, the error is caught. " " [1]: https://github.com/itchyny/lightline.vim -function! lightline#gitdiff#update(soft) - call lightline#gitdiff#write_calculation_to_cache(a:soft) +function! lightline#gitdiff#update(buffers, soft) + for buffer in a:buffers + call lightline#gitdiff#write_calculation_to_cache(buffer, a:soft) + endfor let l:Callback = get(g:, 'lightline#gitdiff#update_callback', { -> lightline#update() }) @@ -29,15 +31,15 @@ endfunction " perform a "soft" write to reduce calls to the function that calculates " changes. This is to minimize overhead. Anyway, the function ensures that " there is data in the cache for the current buffer. -function! lightline#gitdiff#write_calculation_to_cache(soft) abort - if a:soft && has_key(g:lightline#gitdiff#cache, bufnr('%')) +function! lightline#gitdiff#write_calculation_to_cache(buffer, soft) abort + if a:soft && has_key(g:lightline#gitdiff#cache, a:buffer) " b/c there is something in the cache already return endif let l:Calculation = get(g:, 'lightline#gitdiff#algorithm', - \ { -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate() }) - let g:lightline#gitdiff#cache[bufnr('%')] = l:Calculation() + \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) }) + let g:lightline#gitdiff#cache[a:buffer] = l:Calculation(a:buffer) endfunction " format() {{{1 returns the calculated changes of the current buffer in a diff --git a/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim b/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim index db98a84..3dd6cda 100644 --- a/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim +++ b/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim @@ -1,13 +1,13 @@ -" calculate_porcelain() {{{1 transcodes a `git diff --word-diff=porcelain` and +" calculate_porcelain {{{1 transcodes a `git diff --word-diff=porcelain` and " returns a dictionary that tells how many lines in the diff mean Addition, " Deletion or Modification. -function! lightline#gitdiff#algorithms#word_diff_porcelain#calculate() abort - if !lightline#gitdiff#utils#is_git_exectuable() || !lightline#gitdiff#utils#is_inside_work_tree() +function! lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) abort + if !lightline#gitdiff#utils#is_git_exectuable() || !lightline#gitdiff#utils#is_inside_work_tree(a:buffer) " b/c there is nothing that can be done here; the algorithm needs git return {} endif - let l:indicator_groups = s:transcode_diff_porcelain(s:get_diff_porcelain()) + let l:indicator_groups = s:transcode_diff_porcelain(s:get_diff_porcelain(a:buffer)) let l:changes = map(copy(l:indicator_groups), { idx, val -> \ lightline#gitdiff#algorithms#word_diff_porcelain#parse_indicator_group(val) }) @@ -33,11 +33,11 @@ function! lightline#gitdiff#algorithms#word_diff_porcelain#calculate() abort return l:ret endfunction -" get_diff_porcelain() {{{1 returns the output of git's word-diff as list. The +" get_diff_porcelain {{{1 returns the output of git's word-diff as list. The " header of the diff is removed b/c it is not needed. -function! s:get_diff_porcelain() abort - let l:porcelain = systemlist('cd ' . expand('%:p:h:S') . - \ ' && git diff --no-ext-diff --word-diff=porcelain --unified=0 -- ' . expand('%:t:S')) +function! s:get_diff_porcelain(buffer) abort + let l:porcelain = systemlist('cd ' . expand('#' . a:buffer . ':p:h:S') . + \ ' && git diff --no-ext-diff --word-diff=porcelain --unified=0 -- ' . expand('#' . a:buffer . ':t:S')) return l:porcelain[4:] endfunction diff --git a/autoload/lightline/gitdiff/utils.vim b/autoload/lightline/gitdiff/utils.vim index aea36d8..870585f 100644 --- a/autoload/lightline/gitdiff/utils.vim +++ b/autoload/lightline/gitdiff/utils.vim @@ -29,8 +29,8 @@ function! lightline#gitdiff#utils#group_at(f, list, borders) abort return l:grouped_list endfunction -function! lightline#gitdiff#utils#is_inside_work_tree() abort "{{{1 - call system('cd ' . expand('%:p:h:S') . ' && git rev-parse --is-inside-work-tree --prefix ' . expand('%:h:S')) +function! lightline#gitdiff#utils#is_inside_work_tree(buffer) abort "{{{1 + call system('cd ' . expand('#' . a:buffer . ':p:h:S') . ' && git rev-parse --is-inside-work-tree --prefix ' . expand('#' . a:buffer . ':h:S')) return !v:shell_error endfunction diff --git a/plugin/lightline/gitdiff.vim b/plugin/lightline/gitdiff.vim index de892ea..194d691 100644 --- a/plugin/lightline/gitdiff.vim +++ b/plugin/lightline/gitdiff.vim @@ -5,7 +5,9 @@ let g:lightline#gitdiff#cache = {} augroup lightline#gitdiff autocmd! " Update hard b/c buffer is new or changed - autocmd BufReadPost,BufWritePost * :call lightline#gitdiff#update(v:false) + autocmd BufReadPost,BufWritePost * :call lightline#gitdiff#update([bufnr('%')], v:false) " Soft update is possible b/c no buffer new or changed - autocmd BufEnter * :call lightline#gitdiff#update(v:true) + autocmd BufEnter * :call lightline#gitdiff#update([bufnr('%')], v:true) + " Update all cached buffers hard b/c change to repository was made + autocmd BufDelete COMMIT_EDITMSG :call lightline#gitdiff#update(keys(g:lightline#gitdiff#cache), v:false) augroup end From 3ad48c7b92990c4e5255d02122b66c1e50faa9a1 Mon Sep 17 00:00:00 2001 From: Niklaas Baudet von Gersdorff Date: Sun, 26 May 2019 13:13:56 +0200 Subject: [PATCH 4/5] fix(algorithms#numstat): provide buffer number in parameters This allows to use the function on arbitrary buffers -- not only the current one. Refs #9 --- README.md | 2 +- autoload/lightline/gitdiff/algorithms/numstat.vim | 6 ++++-- plugin/lightline/gitdiff.vim | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 16abbba..9367688 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ This resembles the default: ```vim let g:lightline#gitdiff#algorithm = - \ { -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate() } + \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) } ``` Substitute `word_diff_porcelain` with `numstat` if you want to switch -- or diff --git a/autoload/lightline/gitdiff/algorithms/numstat.vim b/autoload/lightline/gitdiff/algorithms/numstat.vim index 885bb76..4fed527 100644 --- a/autoload/lightline/gitdiff/algorithms/numstat.vim +++ b/autoload/lightline/gitdiff/algorithms/numstat.vim @@ -1,13 +1,15 @@ " calculate_numstat {{{1 queries git to get the amount of lines that were " added and/or deleted. It returns a dict with two keys: 'A' and 'D'. 'A' " holds how many lines were added, 'D' holds how many lines were deleted. -function! lightline#gitdiff#algorithms#numstat#calculate() abort +function! lightline#gitdiff#algorithms#numstat#calculate(buffer) abort if !lightline#gitdiff#utils#is_git_exectuable() || !lightline#gitdiff#utils#is_inside_work_tree() " b/c there is nothing that can be done here; the algorithm needs git return {} endif - let l:stats = split(system('cd ' . expand('%:p:h:S') . ' && git diff --no-ext-diff --numstat -- ' . expand('%:t:S'))) + let l:stats = split(system('cd ' . expand('#' . a:buffer . ':p:h:S') + \ . ' && git diff --no-ext-diff --numstat -- ' + \ . expand('#' . a:buffer . ':t:S'))) if len(l:stats) < 2 || join(l:stats[:1], '') !~# '^\d\+$' " b/c there are no changes made, the file is untracked or some error diff --git a/plugin/lightline/gitdiff.vim b/plugin/lightline/gitdiff.vim index 194d691..f2281d1 100644 --- a/plugin/lightline/gitdiff.vim +++ b/plugin/lightline/gitdiff.vim @@ -1,5 +1,5 @@ -" Cache stores the information got from `git --numstat`. The key is the buffer -" number, the value is the amount of lines. +" Cache stores the information got from the algorithms that process the +" `diff`s. The key is the buffer number, the value is the amount of lines. let g:lightline#gitdiff#cache = {} augroup lightline#gitdiff From ff78a3aa4cf38fee30ae3d3c522b519a98df5ebd Mon Sep 17 00:00:00 2001 From: Greg Block Date: Wed, 17 Jun 2020 13:39:49 -0700 Subject: [PATCH 5/5] Add 'g:lightline#gitdiff#show_empty_indicators' option (#17) feat: provide `g:lightline#gitdiff#show_empty_indicators` option to show empty indicators --- README.md | 8 +- autoload/lightline/gitdiff.vim | 21 +- .../lightline/gitdiff/algorithms/numstat.vim | 14 +- .../algorithms/word_diff_porcelain.vim | 16 +- test/lightline-gitdiff.vader | 192 ++++++++++++++++++ 5 files changed, 217 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 9367688..8330bb5 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ By default, the latter one is used because it allows to display modified lines. This resembles the default: ```vim -let g:lightline#gitdiff#algorithm = +let g:LightlineGitDiffAlgorithm = \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) } ``` @@ -115,6 +115,12 @@ provide your own. Take a look at the source of both functions for inspiration or consult me if you need help. I am happy to bundle additional faster and more feature-rich algorithms in the package. +You can show empty indicators (i.e. `A: 0 D: 0 M: 0`) in the following way: + +```vim +let g:lightline#gitdiff#show_empty_indicators = 1 +``` + # How it works / performance In the background, `lightline#gitdiff#get()` calls `git --numstat` or `git diff --git a/autoload/lightline/gitdiff.vim b/autoload/lightline/gitdiff.vim index a8ae45b..5cdd315 100644 --- a/autoload/lightline/gitdiff.vim +++ b/autoload/lightline/gitdiff.vim @@ -34,12 +34,23 @@ endfunction function! lightline#gitdiff#write_calculation_to_cache(buffer, soft) abort if a:soft && has_key(g:lightline#gitdiff#cache, a:buffer) " b/c there is something in the cache already - return + return endif - let l:Calculation = get(g:, 'lightline#gitdiff#algorithm', - \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) }) - let g:lightline#gitdiff#cache[a:buffer] = l:Calculation(a:buffer) + let l:indicator_values = get(g:, 'LightlineGitDiffAlgorithm', + \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) })(a:buffer) + + " If the user doesn't want to show empty indicators, + " then remove the empty indicators returned from the algorithm + if !get(g:, 'lightline#gitdiff#show_empty_indicators', 0) + for key in keys(l:indicator_values) + if l:indicator_values[key] == 0 + unlet l:indicator_values[key] + endif + endfor + endif + + let g:lightline#gitdiff#cache[a:buffer] = l:indicator_values endfunction " format() {{{1 returns the calculated changes of the current buffer in a @@ -62,7 +73,7 @@ endfunction " " In fact, an arbitrary number of changes can be supported. This depends on " the algorithm that is used for calculation -" (`g:lightline#gitdiff#algorithm`). However, this function takes only these +" (`g:LightlineGitDiffAlgorithm`). However, this function takes only these " types of changes into account b/c it only provides default indicators for " these types. If an algorithm does not support a particular type, this is not " an issue; if it supports more types than this function, the additional types diff --git a/autoload/lightline/gitdiff/algorithms/numstat.vim b/autoload/lightline/gitdiff/algorithms/numstat.vim index 4fed527..ae665c3 100644 --- a/autoload/lightline/gitdiff/algorithms/numstat.vim +++ b/autoload/lightline/gitdiff/algorithms/numstat.vim @@ -17,17 +17,5 @@ function! lightline#gitdiff#algorithms#numstat#calculate(buffer) abort return {} endif - let l:ret = {} - - " lines added - if l:stats[0] !=# '0' - let l:ret['A'] = l:stats[0] - endif - - " lines deleted - if l:stats[1] !=# '0' - let l:ret['D'] = l:stats[1] - endif - - return l:ret + return { 'A': l:stats[0], 'D': l:stats[1] } endfunction diff --git a/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim b/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim index 3dd6cda..7a7f432 100644 --- a/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim +++ b/autoload/lightline/gitdiff/algorithms/word_diff_porcelain.vim @@ -16,21 +16,7 @@ function! lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) abo let l:lines_deleted = len(filter(copy(l:changes), { idx, val -> val ==# 'D' })) let l:lines_modified = len(filter(copy(l:changes), { idx, val -> val ==# 'M' })) - let l:ret = {} - - if l:lines_added > 0 - let l:ret['A'] = l:lines_added - endif - - if l:lines_deleted > 0 - let l:ret['D'] = l:lines_deleted - endif - - if l:lines_modified > 0 - let l:ret['M'] = l:lines_modified - endif - - return l:ret + return { 'A': l:lines_added, 'D': l:lines_deleted, 'M': l:lines_modified} endfunction " get_diff_porcelain {{{1 returns the output of git's word-diff as list. The diff --git a/test/lightline-gitdiff.vader b/test/lightline-gitdiff.vader index 09aa45e..b09c653 100644 --- a/test/lightline-gitdiff.vader +++ b/test/lightline-gitdiff.vader @@ -1,2 +1,194 @@ Include (Algorithms): algorithm/parse_indicator_group.vader Include (Utils): utils/group_at.vader + +Before : + if exists('g:LightlineGitDiffAlgorithm') + unlet g:LightlineGitDiffAlgorithm + endif + +" no show_empty_indicators variable +Execute(write_calculation_to_cache(): given no show_empty_indicators variable and an empty result): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return no empty indicators): + AssertEqual {}, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with only added lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 1, 'D': 0, 'M': 0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'A'): + AssertEqual { 'A': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with only deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 1, 'M': 0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'D'): + AssertEqual { 'D': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with only modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M': 1 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'M'): + AssertEqual { 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with added and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 3, 'D': 0, 'M': 1 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'D' indicator): + AssertEqual { 'A': 3, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with deleted and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 2, 'M': 1 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'A' indicator): + AssertEqual { 'D': 2, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with added and deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 4, 'D': 5, 'M': 0 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'M' indicator): + AssertEqual { 'A': 4, 'D': 5 }, actual + +Execute(write_calculation_to_cache(): given no show_empty_indicators variable with added, deleted, and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 9, 'D': 10, 'M': 7 } } + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should not remove any indicators): + AssertEqual { 'A': 9, 'D': 10, 'M': 7 }, actual + +" show_empty_indicators variable == 0 +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with an empty result): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return no empty indicators): + AssertEqual {}, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with only added lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 1, 'D': 0, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'A'): + AssertEqual { 'A': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with only deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 1, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'D'): + AssertEqual { 'D': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with only modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators but 'M'): + AssertEqual { 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with added and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 3, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'D' indicator): + AssertEqual { 'A': 3, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with deleted and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 2, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'A' indicator): + AssertEqual { 'D': 2, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with added and deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 4, 'D': 5, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove only the 'M' indicator): + AssertEqual { 'A': 4, 'D': 5 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 0 with added, deleted, and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 9, 'D': 10, 'M': 7 } } + let g:lightline#gitdiff#show_empty_indicators = 0 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should not remove any indicators): + AssertEqual { 'A': 9, 'D': 10, 'M': 7 }, actual + +" show_empty_indicators variable == 1 +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with an empty result): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M':0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 0, 'M':0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with only added lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 1, 'D': 0, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should remove all indicators): + AssertEqual { 'A': 1, 'D': 0, 'M': 0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with only deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 1, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 1, 'M': 0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with only modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 0, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with added and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 3, 'D': 0, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 3, 'D': 0, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with deleted and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 0, 'D': 2, 'M': 1 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 0, 'D': 2, 'M': 1 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with added and deleted lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 4, 'D': 5, 'M': 0 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 4, 'D': 5, 'M': 0 }, actual + +Execute(write_calculation_to_cache(): given the show_empty_indicators variable equals 1 with added, deleted, and modified lines): + let g:LightlineGitDiffAlgorithm = { -> { 'A': 9, 'D': 10, 'M': 7 } } + let g:lightline#gitdiff#show_empty_indicators = 1 + call g:lightline#gitdiff#write_calculation_to_cache(1, 0) + let actual = get(g:, 'lightline#gitdiff#cache')[1] +Then (should return all indicators): + AssertEqual { 'A': 9, 'D': 10, 'M': 7 }, actual