Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made git commands work despite values of GIT_DIR and GIT_WORK_TREE #523

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions autoload/vundle/installer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ func! s:helptags(rtp) abort
return 1
endf

" ---------------------------------------------------------------------------
" Expand a git command relative to a specified bundle, so that it can be
" executed as a system command.
"
" bundle -- the bundle object to run the git command relative to
" cmd -- the git command (e.g. 'ls-files')
" return -- the fully expanded system command (string)
" ---------------------------------------------------------------------------
func! vundle#installer#expand_git_cmd(bundle, cmd) abort
let out = 'git -C '.vundle#installer#shellesc(a:bundle.path()).' --git-dir=.git/ --work-tree=. '.a:cmd
return out
endf


" ---------------------------------------------------------------------------
" Get the URL for the remote called 'origin' on the repository that
Expand All @@ -330,8 +343,7 @@ endf
" return -- the URL for the origin remote (string)
" ---------------------------------------------------------------------------
func! s:get_current_origin_url(bundle) abort
let cmd = 'cd '.vundle#installer#shellesc(a:bundle.path()).' && git config --get remote.origin.url'
let cmd = vundle#installer#shellesc_cd(cmd)
let cmd = vundle#installer#expand_git_cmd(a:bundle, 'config --get remote.origin.url')
let out = s:strip(s:system(cmd))
return out
endf
Expand All @@ -344,8 +356,7 @@ endf
" return -- A 15 character log sha for the current HEAD
" ---------------------------------------------------------------------------
func! s:get_current_sha(bundle)
let cmd = 'cd '.vundle#installer#shellesc(a:bundle.path()).' && git rev-parse HEAD'
let cmd = vundle#installer#shellesc_cd(cmd)
let cmd = vundle#installer#expand_git_cmd(a:bundle, 'rev-parse HEAD')
let out = s:system(cmd)[0:15]
return out
endf
Expand Down Expand Up @@ -375,14 +386,12 @@ func! s:make_sync_command(bang, bundle) abort
call s:log('> Plugin ' . a:bundle.name . ' new URI: ' . a:bundle.uri)
" Directory names match but the origin remotes are not the same
let cmd_parts = [
\ 'cd '.vundle#installer#shellesc(a:bundle.path()) ,
\ 'git remote set-url origin ' . vundle#installer#shellesc(a:bundle.uri),
\ 'git fetch',
\ 'git reset --hard origin/HEAD',
\ 'git submodule update --init --recursive',
\ vundle#installer#expand_git_cmd(a:bundle, 'remote set-url origin ' . vundle#installer#shellesc(a:bundle.uri)),
\ vundle#installer#expand_git_cmd(a:bundle, 'fetch'),
\ vundle#installer#expand_git_cmd(a:bundle, 'reset --hard origin/HEAD'),
\ vundle#installer#expand_git_cmd(a:bundle, 'submodule update --init --recursive')
\ ]
let cmd = join(cmd_parts, ' && ')
let cmd = vundle#installer#shellesc_cd(cmd)
let initial_sha = ''
return [cmd, initial_sha]
endif
Expand All @@ -393,12 +402,10 @@ func! s:make_sync_command(bang, bundle) abort
endif

let cmd_parts = [
\ 'cd '.vundle#installer#shellesc(a:bundle.path()),
\ 'git pull',
\ 'git submodule update --init --recursive',
\ vundle#installer#expand_git_cmd(a:bundle, 'pull'),
\ vundle#installer#expand_git_cmd(a:bundle, 'submodule update --init --recursive'),
\ ]
let cmd = join(cmd_parts, ' && ')
let cmd = vundle#installer#shellesc_cd(cmd)

let initial_sha = s:get_current_sha(a:bundle)
else
Expand Down Expand Up @@ -473,22 +480,6 @@ func! vundle#installer#shellesc(cmd) abort
endf


" ---------------------------------------------------------------------------
" Fix a cd shell command to be used on Windows.
"
" cmd -- the command to be fixed (string)
" return -- the fixed command (string)
" ---------------------------------------------------------------------------
func! vundle#installer#shellesc_cd(cmd) abort
if ((has('win32') || has('win64')) && empty(matchstr(&shell, 'sh')))
let cmd = substitute(a:cmd, '^cd ','cd /d ','') " add /d switch to change drives
return cmd
else
return a:cmd
endif
endf


" ---------------------------------------------------------------------------
" Make a system call. This can be used to change the way system calls
" are made during developing, without searching the whole code base for
Expand Down
7 changes: 2 additions & 5 deletions autoload/vundle/scripts.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,8 @@ func! s:create_changelog() abort
let updated_sha = bundle_data[1]
let bundle = bundle_data[2]

let cmd = 'cd '.vundle#installer#shellesc(bundle.path()).
\ ' && git log --pretty=format:"%s %an, %ar" --graph '.
\ initial_sha.'..'.updated_sha

let cmd = vundle#installer#shellesc_cd(cmd)
let cmd = vundle#installer#expand_git_cmd(bundle,
\ 'log --pretty=format:"%s %an, %ar" --graph '.initial_sha.'..'.updated_sha)

let updates = system(cmd)

Expand Down