From 5cdde2639ae3a1015224c17946c1f4427403cb89 Mon Sep 17 00:00:00 2001 From: jeremiejig Date: Thu, 17 Sep 2015 19:39:15 +0200 Subject: [PATCH 1/2] bin/install & omf.repo.pull adding -C $git_dir removing pushd and popd --- pkg/omf/cli/omf.install.fish | 4 +--- pkg/omf/cli/omf.repo.pull.fish | 34 ++++++++++++++++++++-------------- pkg/omf/omf.fish | 4 +--- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pkg/omf/cli/omf.install.fish b/pkg/omf/cli/omf.install.fish index adaa242..6e71a68 100644 --- a/pkg/omf/cli/omf.install.fish +++ b/pkg/omf/cli/omf.install.fish @@ -40,9 +40,7 @@ function omf.install -a type_flag name_or_url if test -e $OMF_PATH/$target echo (omf::dim)"Updating $name_or_url $install_type..."(omf::off) - pushd $OMF_PATH/$target - omf.repo.pull - popd + omf.repo.pull $OMF_PATH/$target echo (omf::em)"✔ $name_or_url $install_type up to date."(omf::off) else echo (omf::dim)"Installing $name_or_url $install_type..."(omf::off) diff --git a/pkg/omf/cli/omf.repo.pull.fish b/pkg/omf/cli/omf.repo.pull.fish index 139ef70..837d8d7 100644 --- a/pkg/omf/cli/omf.repo.pull.fish +++ b/pkg/omf/cli/omf.repo.pull.fish @@ -1,42 +1,48 @@ function omf.repo.pull - if test (command git config --get remote.upstream.url) + if test (count $argv) -eq 0 + echo (omf::err)"Argument of omf.repo.pull is the repo path."(omf::off) + return $OMF_MISSING_ARG + end + set -l git_dir $argv[1] + + if test (command git -C "$git_dir" config --get remote.upstream.url) set repository upstream else set repository origin end - set initial_branch (command git symbolic-ref -q --short HEAD); or return $OMF_UNKNOWN_ERR - set initial_revision (command git rev-parse -q --verify HEAD); or return $OMF_UNKNOWN_ERR + set initial_branch (command git -C "$git_dir" symbolic-ref -q --short HEAD); or return $OMF_UNKNOWN_ERR + set initial_revision (command git -C "$git_dir" rev-parse -q --verify HEAD); or return $OMF_UNKNOWN_ERR - if not command git diff --quiet + if not command git -C "$git_dir" diff --quiet echo (omf::em)"Stashing your changes:"(omf::off) - command git status --short --untracked-files + command git -C "$git_dir" status --short --untracked-files - command git stash save --include-untracked --quiet + command git -C "$git_dir" stash save --include-untracked --quiet set stashed true end if test "$initial_branch" != master - command git checkout master --quiet + command git -C "$git_dir" checkout master --quiet end # the refspec ensures that '$repository/master' gets updated - command git pull --rebase --quiet $repository "refs/heads/master:refs/remotes/$repository/master" + command git -C "$git_dir" pull --rebase --quiet $repository "refs/heads/master:refs/remotes/$repository/master" if test $status -eq 2 #SIGINT - command git checkout $initial_branch - command git reset --hard $initial_revision - test "$stashed" = true; and command git stash pop + command git -C "$git_dir" checkout $initial_branch + command git -C "$git_dir" reset --hard $initial_revision + test "$stashed" = true; and command git -C "$git_dir" stash pop end if test "$initial_branch" != master - command git checkout $initial_branch --quiet + command git -C "$git_dir" checkout $initial_branch --quiet end if test "$stashed" = true - command git stash pop --quiet + command git -C "$git_dir" stash pop --quiet echo (omf::em)"Restored your changes:"(omf::off) - command git status --short --untracked-files + command git -C "$git_dir" status --short --untracked-files end return 0 diff --git a/pkg/omf/omf.fish b/pkg/omf/omf.fish index 46ccdb2..1b0f57d 100644 --- a/pkg/omf/omf.fish +++ b/pkg/omf/omf.fish @@ -123,9 +123,8 @@ function omf -d "Oh My Fish" omf.remove_package $argv[2] ; and refresh case "u" "up" "upd" "update" - pushd $OMF_PATH echo (omf::em)"Updating Oh My Fish..."(omf::off) - if omf.repo.pull + if omf.repo.pull $OMF_PATH echo (omf::em)"Oh My Fish is up to date."(omf::off) else echo (omf::err)"Oh My Fish failed to update."(omf::off) @@ -133,7 +132,6 @@ function omf -d "Oh My Fish" end omf.theme (cat $OMF_CONFIG/theme) omf.install_package (omf.list_installed_packages) - popd refresh case "s" "su" "sub" "submit" From 56b1d837e0691bd12cdfa50c04b39d46225ed085 Mon Sep 17 00:00:00 2001 From: jeremiejig Date: Mon, 21 Sep 2015 17:57:17 +0200 Subject: [PATCH 2/2] changing to git -C to git --git-dir work-tree --- bin/install | 8 ++++---- pkg/omf/cli/omf.repo.pull.fish | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bin/install b/bin/install index 14a3105..419157e 100755 --- a/bin/install +++ b/bin/install @@ -58,13 +58,13 @@ omf_install() { die "Could not clone the repository → ${OMF_PATH}:${OMF_REPO_BRANCH}" fi - local git_rev=$(git -C ${OMF_PATH} rev-parse HEAD) >/dev/null 2>&1 - local git_upstream=$(git -C ${OMF_PATH} config remote.upstream.url) + local git_rev=$(git --git-dir ${OMF_PATH}/.git --work-tree ${OMF_PATH} rev-parse HEAD) >/dev/null 2>&1 + local git_upstream=$(git --git-dir ${OMF_PATH}/.git --work-tree ${OMF_PATH} config remote.upstream.url) if [ -z "${git_upstream}" ]; then - git -C ${OMF_PATH} remote add upstream ${git_uri} + git --git-dir ${OMF_PATH}/.git --work-tree ${OMF_PATH} remote add upstream ${git_uri} else - git -C ${OMF_PATH} remote set-url upstream ${git_uri} + git --git-dir ${OMF_PATH}/.git --work-tree ${OMF_PATH} remote set-url upstream ${git_uri} fi echo "Oh My Fish revision id → ${git_rev}" diff --git a/pkg/omf/cli/omf.repo.pull.fish b/pkg/omf/cli/omf.repo.pull.fish index 837d8d7..2c0c0a2 100644 --- a/pkg/omf/cli/omf.repo.pull.fish +++ b/pkg/omf/cli/omf.repo.pull.fish @@ -3,46 +3,46 @@ function omf.repo.pull echo (omf::err)"Argument of omf.repo.pull is the repo path."(omf::off) return $OMF_MISSING_ARG end - set -l git_dir $argv[1] + set -l repo_dir $argv[1] - if test (command git -C "$git_dir" config --get remote.upstream.url) + if test (command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" config --get remote.upstream.url) set repository upstream else set repository origin end - set initial_branch (command git -C "$git_dir" symbolic-ref -q --short HEAD); or return $OMF_UNKNOWN_ERR - set initial_revision (command git -C "$git_dir" rev-parse -q --verify HEAD); or return $OMF_UNKNOWN_ERR + set initial_branch (command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" symbolic-ref -q --short HEAD); or return $OMF_UNKNOWN_ERR + set initial_revision (command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" rev-parse -q --verify HEAD); or return $OMF_UNKNOWN_ERR - if not command git -C "$git_dir" diff --quiet + if not command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" diff --quiet echo (omf::em)"Stashing your changes:"(omf::off) - command git -C "$git_dir" status --short --untracked-files + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" status --short --untracked-files - command git -C "$git_dir" stash save --include-untracked --quiet + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" stash save --include-untracked --quiet set stashed true end if test "$initial_branch" != master - command git -C "$git_dir" checkout master --quiet + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" checkout master --quiet end # the refspec ensures that '$repository/master' gets updated - command git -C "$git_dir" pull --rebase --quiet $repository "refs/heads/master:refs/remotes/$repository/master" + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" pull --rebase --quiet $repository "refs/heads/master:refs/remotes/$repository/master" if test $status -eq 2 #SIGINT - command git -C "$git_dir" checkout $initial_branch - command git -C "$git_dir" reset --hard $initial_revision - test "$stashed" = true; and command git -C "$git_dir" stash pop + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" checkout $initial_branch + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" reset --hard $initial_revision + test "$stashed" = true; and command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" stash pop end if test "$initial_branch" != master - command git -C "$git_dir" checkout $initial_branch --quiet + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" checkout $initial_branch --quiet end if test "$stashed" = true - command git -C "$git_dir" stash pop --quiet + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" stash pop --quiet echo (omf::em)"Restored your changes:"(omf::off) - command git -C "$git_dir" status --short --untracked-files + command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" status --short --untracked-files end return 0