Skip to content

Commit f695463

Browse files
committed
Merge pull request #366 from junegunn/diff-origin
PlugDiff to show pending updates as well
2 parents 6843e5a + e6f4047 commit f695463

File tree

4 files changed

+129
-39
lines changed

4 files changed

+129
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Reload .vimrc and `:PlugInstall` to install plugins.
104104
| `PlugClean[!]` | Remove unused directories (bang version will clean without prompt) |
105105
| `PlugUpgrade` | Upgrade vim-plug itself |
106106
| `PlugStatus` | Check the status of plugins |
107-
| `PlugDiff` | See the updated changes from the previous PlugUpdate |
107+
| `PlugDiff` | Examine changes from the previous update and the pending changes |
108108
| `PlugSnapshot[!] [output path]` | Generate script for restoring the current snapshot of the plugins |
109109

110110
### `Plug` options

plug.vim

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -531,16 +531,20 @@ function! s:syntax()
531531
syn match plugStar /^*/
532532
syn match plugMessage /\(^- \)\@<=.*/
533533
syn match plugName /\(^- \)\@<=[^ ]*:/
534+
syn match plugSha /\%(: \)\@<=[0-9a-z]\{4,}$/
535+
syn match plugTag /(tag: [^)]\+)/
534536
syn match plugInstall /\(^+ \)\@<=[^:]*/
535537
syn match plugUpdate /\(^* \)\@<=[^:]*/
536-
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha
538+
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha,plugTag
537539
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
538540
syn match plugRelDate /([^)]*)$/ contained
539541
syn match plugNotLoaded /(not loaded)$/
540542
syn match plugError /^x.*/
543+
syn match plugH2 /^.*:\n-\+$/
541544
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
542545
hi def link plug1 Title
543546
hi def link plug2 Repeat
547+
hi def link plugH2 Type
544548
hi def link plugX Exception
545549
hi def link plugBracket Structure
546550
hi def link plugNumber Number
@@ -557,6 +561,7 @@ function! s:syntax()
557561
hi def link plugError Error
558562
hi def link plugRelDate Comment
559563
hi def link plugSha Identifier
564+
hi def link plugTag Constant
560565

561566
hi def link plugNotLoaded Comment
562567
endfunction
@@ -1993,41 +1998,63 @@ function! s:section(flags)
19931998
call search('\(^[x-] \)\@<=[^:]\+:', a:flags)
19941999
endfunction
19952000

1996-
function! s:diff()
1997-
call s:prepare()
1998-
call append(0, 'Collecting updated changes ...')
1999-
normal! gg
2000-
redraw
2001+
function! s:format_git_log(line)
2002+
let [sha, refs, subject, date] = split(a:line, nr2char(1))
2003+
let tag = matchstr(refs, 'tag: [^,)]\+')
2004+
let tag = empty(tag) ? ' ' : ' ('.tag.') '
2005+
return printf(' %s%s%s (%s)', sha, tag, subject, date)
2006+
endfunction
20012007

2002-
let cnt = 0
2003-
for [k, v] in filter(items(g:plugs), '!has_key(v:val[1], "commit")')
2004-
if !isdirectory(v.dir) || !s:is_managed(k)
2005-
continue
2006-
endif
2008+
function! s:append_ul(lnum, text)
2009+
call append(a:lnum, ['', a:text, repeat('-', len(a:text))])
2010+
endfunction
20072011

2008-
let diff = s:system_chomp('git log --left-only --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"', v.dir)
2009-
if !empty(diff)
2010-
call append(1, '')
2011-
call append(2, '- '.k.':')
2012-
call append(3, map(s:lines(diff), '" ". v:val'))
2013-
let cnt += 1
2014-
normal! gg
2012+
function! s:diff()
2013+
call s:prepare()
2014+
call append(0, ['Collecting changes ...', ''])
2015+
let cnts = [0, 0]
2016+
let bar = ''
2017+
let total = filter(copy(g:plugs), 's:is_managed(v:key) && isdirectory(v:val.dir)')
2018+
call s:progress_bar(2, bar, len(total))
2019+
for origin in [1, 0]
2020+
call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:')
2021+
for [k, v] in reverse(sort(items(filter(copy(total), (origin ? '' : '!').'(has_key(v:val, "commit") || has_key(v:val, "tag"))'))))
2022+
let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..'
2023+
let diff = s:system_chomp('git log --pretty=format:"%h%x01%d%x01%s%x01%cr" '.s:shellesc(range), v.dir)
2024+
if !empty(diff)
2025+
let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : ''
2026+
call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)')))
2027+
let cnts[origin] += 1
2028+
endif
2029+
let bar .= '='
2030+
call s:progress_bar(2, bar, len(total))
2031+
normal! 2G
20152032
redraw
2033+
endfor
2034+
if !cnts[origin]
2035+
call append(5, ['', 'N/A'])
20162036
endif
20172037
endfor
2038+
call setline(1, printf('%d plugin(s) updated.', cnts[0])
2039+
\ . (cnts[1] ? printf(' %d plugin(s) have pending updates.', cnts[1]) : ''))
20182040

2019-
call setline(1, cnt == 0 ? 'No updates.' : 'Last update:')
2020-
nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr>
2021-
nnoremap <silent> <buffer> o :silent! call <SID>preview_commit()<cr>
2022-
nnoremap <silent> <buffer> X :call <SID>revert()<cr>
2023-
normal! gg
2024-
setlocal nomodifiable
2025-
if cnt > 0
2041+
if cnts[0] || cnts[1]
2042+
nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr>
2043+
nnoremap <silent> <buffer> o :silent! call <SID>preview_commit()<cr>
2044+
endif
2045+
if cnts[0]
2046+
nnoremap <silent> <buffer> X :call <SID>revert()<cr>
20262047
echo "Press 'X' on each block to revert the update"
20272048
endif
2049+
normal! gg
2050+
setlocal nomodifiable
20282051
endfunction
20292052

20302053
function! s:revert()
2054+
if search('^Pending updates', 'bnW')
2055+
return
2056+
endif
2057+
20312058
let name = s:find_name(line('.'))
20322059
if empty(name) || !has_key(g:plugs, name) ||
20332060
\ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y'

test/run

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ clone() {
1818
fi
1919
}
2020

21-
clone_repos() {
21+
clone_repos() (
2222
cd /tmp
2323
mkdir -p junegunn vim-scripts jg
2424
for repo in vader.vim goyo.vim rust.vim seoul256.vim vim-easy-align vim-fnr \
@@ -31,11 +31,9 @@ clone_repos() {
3131

3232
clone junegunn/vim-emoji jg/vim-emoji
3333
cd junegunn/seoul256.vim && git checkout no-t_co && git checkout master
34+
)
3435

35-
cd "$BASE"
36-
}
37-
38-
make_dirs() {
36+
make_dirs() (
3937
rm -rf "$PLUG_FIXTURES/$1"
4038
mkdir -p "$PLUG_FIXTURES/$1"
4139
cd "$PLUG_FIXTURES/$1"
@@ -51,9 +49,13 @@ make_dirs() {
5149
call add(g:total_order, s:name)
5250
EOF
5351
done
52+
)
5453

55-
cd "$BASE"
56-
}
54+
gitinit() (
55+
cd "$PLUG_FIXTURES/$1"
56+
git init
57+
git commit -m 'commit' --allow-empty
58+
)
5759

5860
prepare() {
5961
make_dirs xxx/ xxx
@@ -62,9 +64,11 @@ prepare() {
6264
cat > "$PLUG_FIXTURES/xxx/doc/xxx.txt" << DOC
6365
hello *xxx*
6466
DOC
67+
gitinit xxx
6568

6669
make_dirs yyy/ yyy
6770
make_dirs yyy/after yyy
71+
gitinit yyy
6872

6973
make_dirs z1/ z1
7074
make_dirs z2/ z2

test/workflow.vader

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,16 @@ Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
262262
PlugUpdate
263263
AssertExpect 'Already up-to-date', 2
264264
normal D
265-
AssertEqual 'No updates.', getline(1)
265+
AssertEqual '0 plugin(s) updated.', getline(1)
266266
q
267267

268268
Execute (PlugDiff - 'No updates.'):
269269
PlugDiff
270-
AssertEqual 'No updates.', getline(1)
270+
Log getline(1, '$')
271+
AssertEqual '0 plugin(s) updated.', getline(1)
272+
Assert empty(mapcheck('o'))
273+
Assert empty(mapcheck('X'))
274+
Assert empty(mapcheck("\<cr>"))
271275
q
272276

273277
Execute (New commits on remote, PlugUpdate, then PlugDiff):
@@ -281,7 +285,7 @@ Execute (New commits on remote, PlugUpdate, then PlugDiff):
281285

282286
" Now we have updates
283287
normal D
284-
AssertEqual 'Last update:', getline(1)
288+
AssertEqual '2 plugin(s) updated.', getline(1)
285289

286290
" Preview commit
287291
silent! wincmd P
@@ -367,7 +371,58 @@ Execute (contd. PlugDiff should not show inverted history):
367371
" PlugDiff should not report the changes i.e. git log --left-only
368372
PlugDiff
369373
Log getline(1, '$')
370-
AssertEqual 'No updates.', getline(1)
374+
AssertEqual '0 plugin(s) updated.', getline(1)
375+
q
376+
377+
**********************************************************************
378+
~ PlugDiff to see the pending changes
379+
**********************************************************************
380+
381+
Execute (PlugDiff):
382+
call plug#begin()
383+
call plug#end()
384+
PlugClean!
385+
386+
call plug#begin()
387+
Plug 'file://'.expand('$PLUG_FIXTURES').'/xxx'
388+
Plug 'file://'.expand('$PLUG_FIXTURES').'/yyy'
389+
call plug#end()
390+
PlugInstall
391+
Log getline(1, '$')
392+
393+
call system('cd "$PLUG_FIXTURES/xxx" && git commit --allow-empty -m update-xxx && git tag -f xxx')
394+
call system('cd "$PLUG_FIXTURES/yyy" && git tag -f yyy && git commit --allow-empty -m update-yyy && git tag -f zzz')
395+
396+
let g:plugs.yyy.tag = 'yyy'
397+
PlugUpdate
398+
Log getline(1, '$')
399+
400+
PlugDiff
401+
" 1 plugin(s) updated. 1 plugin(s) have pending updates.
402+
" [==]
403+
"
404+
" Last update:
405+
" ------------
406+
"
407+
" - xxx:
408+
" 166cfff (tag: xxx) update-xxx (1 second ago)
409+
"
410+
" Pending updates:
411+
" ----------------
412+
"
413+
" - yyy: (tag: yyy)
414+
" c0a064b (tag: zzz) update-yyy (1 second ago)
415+
"
416+
Log getline(1, '$')
417+
AssertEqual 15, line('$')
418+
AssertEqual '1 plugin(s) updated. 1 plugin(s) have pending updates.', getline(1)
419+
AssertEqual '[==]', getline(2)
420+
AssertEqual '- yyy: (tag: yyy)', getline(13)
421+
Assert getline(8) =~ '(tag: xxx)'
422+
Assert getline(14) =~ '(tag: zzz)'
423+
Assert !empty(mapcheck('o'))
424+
Assert !empty(mapcheck('X'))
425+
Assert !empty(mapcheck("\<cr>"))
371426
q
372427

373428
**********************************************************************
@@ -1258,9 +1313,13 @@ Execute (Commit hash support):
12581313
AssertEqual [' PlugUpdate required.',
12591314
\'- vim-emoji: OK'], getline(6, '$')
12601315

1261-
" Plugins with commit option should not appear in PlugDiff output
1316+
" PlugDiff should show pending updates for vim-emoji
12621317
PlugDiff
1263-
AssertEqual 'No updates.', getline(1)
1318+
Log getline(1, '$')
1319+
AssertEqual '0 plugin(s) updated. 1 plugin(s) have pending updates.', getline(1)
1320+
Assert !empty(mapcheck('o'))
1321+
Assert empty(mapcheck('X'))
1322+
Assert !empty(mapcheck("\<cr>"))
12641323

12651324
" Nor in PlugSnapshot output
12661325
PlugSnapshot

0 commit comments

Comments
 (0)