From a92a749e822fc475a17ad1dd6cde0fdda353e27e Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Tue, 16 Feb 2016 14:36:29 +0900 Subject: [PATCH] Remove git -C to improve support in exotic systems. --- functions/__fisher_path_from_url.fish | 14 ++++++-------- functions/__fisher_path_update.fish | 8 ++++++-- functions/__fisher_url_from_path.fish | 6 +++++- test/helpers/git-ls-remote.fish | 6 +++--- test/path-from-url.fish | 17 +++++++++++------ test/path-update.fish | 20 ++++++++++++++------ test/url-from-path-git.fish | 7 +++++-- 7 files changed, 50 insertions(+), 28 deletions(-) diff --git a/functions/__fisher_path_from_url.fish b/functions/__fisher_path_from_url.fish index 7a27d88..5eda3da 100644 --- a/functions/__fisher_path_from_url.fish +++ b/functions/__fisher_path_from_url.fish @@ -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 diff --git a/functions/__fisher_path_update.fish b/functions/__fisher_path_update.fish index 254c543..c6d1f08 100644 --- a/functions/__fisher_path_update.fish +++ b/functions/__fisher_path_update.fish @@ -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 diff --git a/functions/__fisher_url_from_path.fish b/functions/__fisher_url_from_path.fish index 03c07ce..88eb52f 100644 --- a/functions/__fisher_url_from_path.fish +++ b/functions/__fisher_url_from_path.fish @@ -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 diff --git a/test/helpers/git-ls-remote.fish b/test/helpers/git-ls-remote.fish index 10be02d..225fb51 100644 --- a/test/helpers/git-ls-remote.fish +++ b/test/helpers/git-ls-remote.fish @@ -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 diff --git a/test/path-from-url.fish b/test/path-from-url.fish index 6a4ab1e..28f381b 100644 --- a/test/path-from-url.fish +++ b/test/path-from-url.fish @@ -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 diff --git a/test/path-update.fish b/test/path-update.fish index 0bcfe58..a0ed544 100644 --- a/test/path-update.fish +++ b/test/path-update.fish @@ -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 diff --git a/test/url-from-path-git.fish b/test/url-from-path-git.fish index 09c32b2..ff2a601 100644 --- a/test/url-from-path-git.fish +++ b/test/url-from-path-git.fish @@ -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 @ 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