Remove git -C to improve support in exotic systems.

This commit is contained in:
Jorge Bucaran 2016-02-16 14:36:29 +09:00
parent 97b30dc97f
commit a92a749e82
No known key found for this signature in database
GPG key ID: E54BA3C0E646DB30
7 changed files with 50 additions and 28 deletions

View file

@ -1,17 +1,15 @@
function __fisher_path_from_url -a url
# What is the difference between path-from-url and url-from-path?
# Both functions use 'git ... --get-url'. The first one compares the given URL with
# the ls-remote of each repo in the cache and returns the path of the first match.
# The other one returns the ls-remote of the given path.
for file in $fisher_cache/*
pushd $file
switch "$url"
case (git -C $file ls-remote --get-url)
case (git ls-remote --get-url)
printf "%s\n" $file
popd
return
end
popd
end
return 1

View file

@ -1,4 +1,8 @@
function __fisher_path_update -a path
git -C $path checkout master --quiet ^ /dev/null
git -C $path pull --rebase origin master --quiet
pushd $path
git checkout master --quiet ^ /dev/null
git pull --rebase origin master --quiet
popd
end

View file

@ -6,7 +6,11 @@ function __fisher_url_from_path -a path
if test -L "$path"
readlink $path
else
set -l url (git -C "$path" ls-remote --get-url ^ /dev/null)
pushd $path
set -l url (git ls-remote --get-url ^ /dev/null)
popd
if test -z "$url"
return 1

View file

@ -1,6 +1,6 @@
function -S git -a 1 file ctx action
if test "$ctx" = "ls-remote" -a "$action" = --get-url
switch (basename "$file")
function -S git
if contains -- ls-remote $argv
switch (basename (pwd))
case foo
echo https://github.com/foo/foo
case bar

View file

@ -1,8 +1,5 @@
set -l path $DIRNAME/.t-$TESTNAME-(random)
# What is the difference between path-from-url and url-from-path?
# See __fisher_path_from_url.fish for the answer.
function -S setup
mkdir -p $path/cache/{foo,bar,baz}
set -g fisher_cache $path/cache
@ -19,14 +16,22 @@ end
for plugin in foo bar baz
test "$TESTNAME - Get cache path from url <$plugin> using Git"
$path/cache/$plugin = (__fisher_path_from_url https://github.com/$plugin/$plugin)
$path/cache/$plugin = (
__fisher_path_from_url https://github.com/$plugin/$plugin
)
end
end
test "$TESTNAME - Fail if no url does not match any of the plugins ls-remote"
(__fisher_path_from_url https://github.com/norf/norf > /dev/null; printf $status) -eq 1
1 -eq (
__fisher_path_from_url https://github.com/norf/norf > /dev/null
printf $status
)
end
test "$TESTNAME - Succeed if a url matches any the plugins ls-remote"
(__fisher_path_from_url https://github.com/bar/bar > /dev/null; printf $status) -eq 0
0 -eq (
__fisher_path_from_url https://github.com/bar/bar > /dev/null
printf $status
)
end

View file

@ -1,18 +1,26 @@
set -g path $DIRNAME/.t-$TESTNAME-(random)
function -S setup
mkdir -p $path/foo
function git
switch "$argv"
case "-C foo/bar checkout master --quiet"
printf checkout-
case "-C foo/bar pull --rebase origin master --quiet"
printf pull-rebase
if test (pwd) = $path/foo
switch "$argv"
case "checkout master --quiet"
printf checkout-
case "pull --rebase origin master --quiet"
printf pull-rebase
end
end
end
end
function -S teardown
functions -e git
rm -rf $path
end
test "$TESTNAME - Use Git to update given path"
"checkout-pull-rebase" = (__fisher_path_update foo/bar)
"checkout-pull-rebase" = (__fisher_path_update $path/foo)
end

View file

@ -1,24 +1,27 @@
set -l path $DIRNAME/.t-$TESTNAME-(random)
set -l gist_plugin norf
function -S setup
mkdir -p $path/cache/{foo,bar,baz,$gist_plugin}
source $DIRNAME/helpers/git-ls-remote.fish
end
function -S teardown
functions -e git
rm -rf $path
end
for plugin in foo bar baz
test "$TESTNAME - Get URL from repo's path in the cache ($plugin)"
"https://github.com/$plugin/$plugin" = (
__fisher_url_from_path ...cache/$plugin
__fisher_url_from_path $path/cache/$plugin
)
end
end
test "$TESTNAME - Get <plugin>@<URL> for URLs of GitHub gists"
"$gist_plugin@https://gist.github.com/$gist_plugin" = (
__fisher_url_from_path ...cache/$gist_plugin
__fisher_url_from_path $path/cache/$gist_plugin
)
end