From d53d5a976f06c89111530640ce43979b6cf9172b Mon Sep 17 00:00:00 2001 From: David Barnett Date: Fri, 28 Aug 2020 18:43:05 -0700 Subject: [PATCH 1/9] Add |:Plug| tag in help docs (#951) --- doc/plug.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/plug.txt b/doc/plug.txt index 3740e03..cf3317e 100644 --- a/doc/plug.txt +++ b/doc/plug.txt @@ -204,6 +204,7 @@ Reload .vimrc and `:PlugInstall` to install plugins. < Plug options >______________________________________________________________~ *plug-options* + *:Plug* ------------------------+----------------------------------------------- Option | Description ~ From 4a3c5e7ac280b15d7279ef48e6a915cf49023cc6 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 27 Aug 2020 14:30:43 +0900 Subject: [PATCH 2/9] Support non-master default branch --- plug.vim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plug.vim b/plug.vim index 7914bfe..31c0786 100644 --- a/plug.vim +++ b/plug.vim @@ -106,7 +106,7 @@ if s:is_win && &shellslash else let s:me = resolve(expand(':p')) endif -let s:base_spec = { 'branch': 'master', 'frozen': 0 } +let s:base_spec = { 'branch': '', 'frozen': 0 } let s:TYPE = { \ 'string': type(''), \ 'list': type([]), @@ -649,7 +649,7 @@ function! s:parse_options(arg) call extend(opts, a:arg) for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as'] if has_key(opts, opt) - \ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt])) + \ && (type(opts[opt]) != s:TYPE.string || (opt != 'branch' && empty(opts[opt]))) throw printf(opt_errfmt, opt, 'string') endif endfor @@ -1206,7 +1206,10 @@ function! s:update_finish() call s:log4(name, 'Checking out '.tag) let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir) else - let branch = get(spec, 'branch', 'master') + let branch = get(spec, 'branch', '') + if empty(branch) + let branch = s:git_get_branch(spec.dir) + endif call s:log4(name, 'Merging origin/'.s:esc(branch)) let out = s:system('git checkout -q '.plug#shellescape(branch).' -- 2>&1' \. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only '.plug#shellescape('origin/'.branch).' 2>&1')), spec.dir) From 5706f70f8f4eaaf306bbac49bec1259bc43b7667 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 27 Aug 2020 21:59:09 +0900 Subject: [PATCH 3/9] Add missing function --- plug.vim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plug.vim b/plug.vim index 31c0786..4b1bc7f 100644 --- a/plug.vim +++ b/plug.vim @@ -2211,6 +2211,14 @@ function! s:system_chomp(...) return v:shell_error ? '' : substitute(ret, '\n$', '', '') endfunction +function! s:git_get_branch(dir) + let result = s:lines(s:system('git symbolic-ref --short HEAD', a:dir)) + if v:shell_error + return '' + endif + return result[-1] +endfunction + function! s:git_validate(spec, check_branch) let err = '' if isdirectory(a:spec.dir) @@ -2234,6 +2242,9 @@ function! s:git_validate(spec, check_branch) endif elseif a:check_branch let branch = result[0] + if empty(branch) + let branch = 'HEAD' + endif " Check tag if has_key(a:spec, 'tag') let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir) @@ -2242,7 +2253,7 @@ function! s:git_validate(spec, check_branch) \ (empty(tag) ? 'N/A' : tag), a:spec.tag) endif " Check branch - elseif a:spec.branch !=# branch + elseif a:spec.branch != '' && a:spec.branch !=# branch let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', \ branch, a:spec.branch) endif From 588467903b39960a643519fb627b5997d8e70328 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 27 Aug 2020 22:48:30 +0900 Subject: [PATCH 4/9] Use branch --- plug.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plug.vim b/plug.vim index 4b1bc7f..d27dc75 100644 --- a/plug.vim +++ b/plug.vim @@ -2260,7 +2260,7 @@ function! s:git_validate(spec, check_branch) if empty(err) let [ahead, behind] = split(s:lastline(s:system([ \ 'git', 'rev-list', '--count', '--left-right', - \ printf('HEAD...origin/%s', a:spec.branch) + \ printf('HEAD...origin/%s', branch) \ ], a:spec.dir)), '\t') if !v:shell_error && ahead if behind @@ -2268,11 +2268,11 @@ function! s:git_validate(spec, check_branch) " pushable (and probably not that messed up). let err = printf( \ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n" - \ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', a:spec.branch, ahead, behind) + \ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', branch, ahead, behind) else let err = printf("Ahead of origin/%s by %d commit(s).\n" \ .'Cannot update until local changes are pushed.', - \ a:spec.branch, ahead) + \ branch, ahead) endif endif endif From 6fa6475fee9e0f133f3d7535b143bfdc16650a4b Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 29 Aug 2020 01:38:33 +0900 Subject: [PATCH 5/9] User-specified branch name should not be empty --- plug.vim | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plug.vim b/plug.vim index d27dc75..7ae9962 100644 --- a/plug.vim +++ b/plug.vim @@ -646,25 +646,25 @@ function! s:parse_options(arg) endif let opts.tag = a:arg elseif type == s:TYPE.dict - call extend(opts, a:arg) for opt in ['branch', 'tag', 'commit', 'rtp', 'dir', 'as'] - if has_key(opts, opt) - \ && (type(opts[opt]) != s:TYPE.string || (opt != 'branch' && empty(opts[opt]))) + if has_key(a:arg, opt) + \ && (type(a:arg[opt]) != s:TYPE.string || empty(a:arg[opt])) throw printf(opt_errfmt, opt, 'string') endif endfor for opt in ['on', 'for'] - if has_key(opts, opt) - \ && type(opts[opt]) != s:TYPE.list - \ && (type(opts[opt]) != s:TYPE.string || empty(opts[opt])) + if has_key(a:arg, opt) + \ && type(a:arg[opt]) != s:TYPE.list + \ && (type(a:arg[opt]) != s:TYPE.string || empty(a:arg[opt])) throw printf(opt_errfmt, opt, 'string or list') endif endfor - if has_key(opts, 'do') - \ && type(opts.do) != s:TYPE.funcref - \ && (type(opts.do) != s:TYPE.string || empty(opts.do)) + if has_key(a:arg, 'do') + \ && type(a:arg.do) != s:TYPE.funcref + \ && (type(a:arg.do) != s:TYPE.string || empty(a:arg.do)) throw printf(opt_errfmt, 'do', 'string or funcref') endif + call extend(opts, a:arg) if has_key(opts, 'dir') let opts.dir = s:dirpath(s:plug_expand(opts.dir)) endif From 95ef5e8d5f1a8366171c1b74e074e028c8474175 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 29 Aug 2020 01:39:29 +0900 Subject: [PATCH 6/9] PlugDiff should be able to find pending updates # We need the name of the default branch of origin git checkout some-tag-or-commit git log ..origin/master --- plug.vim | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/plug.vim b/plug.vim index 7ae9962..9d161e0 100644 --- a/plug.vim +++ b/plug.vim @@ -2588,6 +2588,18 @@ function! s:append_ul(lnum, text) call append(a:lnum, ['', a:text, repeat('-', len(a:text))]) endfunction +function! s:git_origin_branch(spec) + if len(a:spec.branch) + return a:spec.branch + endif + + let origin_head = a:spec.dir.'/.git/refs/remotes/origin/HEAD' + if !filereadable(origin_head) + return '' + endif + return split(readfile(origin_head)[0], '/')[-1] +endfunction + function! s:diff() call s:prepare() call append(0, ['Collecting changes ...', '']) @@ -2602,20 +2614,23 @@ function! s:diff() endif call s:append_ul(2, origin ? 'Pending updates:' : 'Last update:') for [k, v] in plugs - let range = origin ? '..origin/'.v.branch : 'HEAD@{1}..' - let cmd = ['git', 'log', '--graph', '--color=never'] - if s:git_version_requirement(2, 10, 0) - call add(cmd, '--no-show-signature') - endif - call extend(cmd, ['--pretty=format:%x01%h%x01%d%x01%s%x01%cr', range]) - if has_key(v, 'rtp') - call extend(cmd, ['--', v.rtp]) - endif - let diff = s:system_chomp(cmd, v.dir) - if !empty(diff) - let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' - call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) - let cnts[origin] += 1 + let branch = s:git_origin_branch(v) + if len(branch) + let range = origin ? '..origin/'.branch : 'HEAD@{1}..' + let cmd = ['git', 'log', '--graph', '--color=never'] + if s:git_version_requirement(2, 10, 0) + call add(cmd, '--no-show-signature') + endif + call extend(cmd, ['--pretty=format:%x01%h%x01%d%x01%s%x01%cr', range]) + if has_key(v, 'rtp') + call extend(cmd, ['--', v.rtp]) + endif + let diff = s:system_chomp(cmd, v.dir) + if !empty(diff) + let ref = has_key(v, 'tag') ? (' (tag: '.v.tag.')') : has_key(v, 'commit') ? (' '.v.commit) : '' + call append(5, extend(['', '- '.k.':'.ref], map(s:lines(diff), 's:format_git_log(v:val)'))) + let cnts[origin] += 1 + endif endif let bar .= '=' call s:progress_bar(2, bar, len(total)) From 49be3a8ca930197de69f82f59b2bcac00bc25b2d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 29 Aug 2020 02:00:01 +0900 Subject: [PATCH 7/9] Use branch name of origin if not specified --- plug.vim | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/plug.vim b/plug.vim index 9d161e0..a4a1c08 100644 --- a/plug.vim +++ b/plug.vim @@ -1206,10 +1206,7 @@ function! s:update_finish() call s:log4(name, 'Checking out '.tag) let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir) else - let branch = get(spec, 'branch', '') - if empty(branch) - let branch = s:git_get_branch(spec.dir) - endif + let branch = s:git_origin_branch(spec) call s:log4(name, 'Merging origin/'.s:esc(branch)) let out = s:system('git checkout -q '.plug#shellescape(branch).' -- 2>&1' \. (has_key(s:update.new, name) ? '' : ('&& git merge --ff-only '.plug#shellescape('origin/'.branch).' 2>&1')), spec.dir) @@ -2211,12 +2208,20 @@ function! s:system_chomp(...) return v:shell_error ? '' : substitute(ret, '\n$', '', '') endfunction -function! s:git_get_branch(dir) - let result = s:lines(s:system('git symbolic-ref --short HEAD', a:dir)) - if v:shell_error - return '' +function! s:git_origin_branch(spec) + if len(a:spec.branch) + return a:spec.branch endif - return result[-1] + + " The file may not be present if this is a local repository + let origin_head = a:spec.dir.'/.git/refs/remotes/origin/HEAD' + if filereadable(origin_head) + return split(readfile(origin_head)[0], 'refs/remotes/origin/')[-1] + endif + + " The command may not return the name of a branch in detached HEAD state + let result = s:lines(s:system('git symbolic-ref --short HEAD', a:spec.dir)) + return v:shell_error ? '' : result[-1] endfunction function! s:git_validate(spec, check_branch) @@ -2241,11 +2246,9 @@ function! s:git_validate(spec, check_branch) \ 'PlugUpdate required.'], "\n") endif elseif a:check_branch - let branch = result[0] - if empty(branch) - let branch = 'HEAD' - endif + let current_branch = result[0] " Check tag + let origin_branch = s:git_origin_branch(a:spec) if has_key(a:spec, 'tag') let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir) if a:spec.tag !=# tag && a:spec.tag !~ '\*' @@ -2253,14 +2256,14 @@ function! s:git_validate(spec, check_branch) \ (empty(tag) ? 'N/A' : tag), a:spec.tag) endif " Check branch - elseif a:spec.branch != '' && a:spec.branch !=# branch + elseif origin_branch !=# current_branch let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', - \ branch, a:spec.branch) + \ current_branch, origin_branch) endif if empty(err) let [ahead, behind] = split(s:lastline(s:system([ \ 'git', 'rev-list', '--count', '--left-right', - \ printf('HEAD...origin/%s', branch) + \ printf('HEAD...origin/%s', origin_branch) \ ], a:spec.dir)), '\t') if !v:shell_error && ahead if behind @@ -2268,11 +2271,11 @@ function! s:git_validate(spec, check_branch) " pushable (and probably not that messed up). let err = printf( \ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n" - \ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', branch, ahead, behind) + \ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', origin_branch, ahead, behind) else let err = printf("Ahead of origin/%s by %d commit(s).\n" \ .'Cannot update until local changes are pushed.', - \ branch, ahead) + \ origin_branch, ahead) endif endif endif @@ -2588,18 +2591,6 @@ function! s:append_ul(lnum, text) call append(a:lnum, ['', a:text, repeat('-', len(a:text))]) endfunction -function! s:git_origin_branch(spec) - if len(a:spec.branch) - return a:spec.branch - endif - - let origin_head = a:spec.dir.'/.git/refs/remotes/origin/HEAD' - if !filereadable(origin_head) - return '' - endif - return split(readfile(origin_head)[0], '/')[-1] -endfunction - function! s:diff() call s:prepare() call append(0, ['Collecting changes ...', '']) From e8892a9bef0a77753abb82133b2545c358b3f71a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 29 Aug 2020 02:02:20 +0900 Subject: [PATCH 8/9] Update test cases --- test/workflow.vader | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/workflow.vader b/test/workflow.vader index 8ea5114..f9ab383 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -68,13 +68,13 @@ Execute (Test Plug command): " Git URI Plug 'file:///tmp/vim-plug-test/jg/vim-emoji' AssertEqual 'file:///tmp/vim-plug-test/jg/vim-emoji', g:plugs['vim-emoji'].uri - AssertEqual 'master', g:plugs['vim-emoji'].branch + AssertEqual '', g:plugs['vim-emoji'].branch AssertEqual join([g:temp_plugged, 'vim-emoji/'], '/'), g:plugs['vim-emoji'].dir " vim-scripts/ Plug 'vim-scripts/beauty256' AssertEqual 'file:///tmp/vim-plug-test/vim-scripts/beauty256', g:plugs.beauty256.uri - AssertEqual 'master', g:plugs.beauty256.branch + AssertEqual '', g:plugs.beauty256.branch AssertEqual 4, len(g:plugs) From a9bf5bd72212ff7cf9e9e863c365a3464faa2426 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 29 Aug 2020 17:05:44 +0900 Subject: [PATCH 9/9] "non-master branch" -> "non-default branch" --- README.md | 2 +- doc/plug.txt | 2 +- plug.vim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 955bfc8..e2f7b64 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets' Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } Plug 'tpope/vim-fireplace', { 'for': 'clojure' } -" Using a non-master branch +" Using a non-default branch Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } " Using a tagged release; wildcard allowed (requires git 1.9.2 or above) diff --git a/doc/plug.txt b/doc/plug.txt index cf3317e..db0e4ef 100644 --- a/doc/plug.txt +++ b/doc/plug.txt @@ -163,7 +163,7 @@ Example~ Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } Plug 'tpope/vim-fireplace', { 'for': 'clojure' } - " Using a non-master branch + " Using a non-default branch Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } " Using a tagged release; wildcard allowed (requires git 1.9.2 or above) diff --git a/plug.vim b/plug.vim index a4a1c08..c29b9a2 100644 --- a/plug.vim +++ b/plug.vim @@ -25,7 +25,7 @@ " Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " Plug 'tpope/vim-fireplace', { 'for': 'clojure' } " -" " Using a non-master branch +" " Using a non-default branch " Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' } " " " Using a tagged release; wildcard allowed (requires git 1.9.2 or above)