diff --git a/README.md b/README.md index f452d9e..8330bb5 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 favourite plugin manager and add `lightline#gitdiff#get` to your -lightline e.g.: +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.) + +### 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,53 @@ 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:LightlineGitDiffAlgorithm = + \ { buffer -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate(buffer) } +``` + +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. + +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, 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..5cdd315 100644 --- a/autoload/lightline/gitdiff.vim +++ b/autoload/lightline/gitdiff.vim @@ -10,15 +10,20 @@ 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) +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') + 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 @@ -26,15 +31,26 @@ 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 + return + endif + + 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 l:Calculation = get(g:, 'lightline#gitdiff#algorithm', - \ { -> lightline#gitdiff#algorithms#word_diff_porcelain#calculate() }) - let g:lightline#gitdiff#cache[bufnr('%')] = l:Calculation() + let g:lightline#gitdiff#cache[a:buffer] = l:indicator_values endfunction " format() {{{1 returns the calculated changes of the current buffer in a @@ -57,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 885bb76..ae665c3 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 @@ -15,17 +17,5 @@ function! lightline#gitdiff#algorithms#numstat#calculate() 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 db98a84..7a7f432 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) }) @@ -16,28 +16,14 @@ function! lightline#gitdiff#algorithms#word_diff_porcelain#calculate() abort 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 +" 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..f2281d1 100644 --- a/plugin/lightline/gitdiff.vim +++ b/plugin/lightline/gitdiff.vim @@ -1,11 +1,13 @@ -" 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 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 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