oh-my-fish/pkg/omf/cli/omf.repo.pull.fish
Bruno Pinto 9cc8ee5a82 Stash does not support --git-dir
Stash is a shell script that does not support `--git-dir`, not even on
latest versions. We need to use `git -C` which was only added on recent
versions of `git`.

`omf update` will fail in case omf need needs to run `git stash` and
git is not compatible.
2015-10-02 21:16:50 +01:00

50 lines
1.9 KiB
Fish

function omf.repo.pull
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 repo_dir $argv[1]
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 --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 --git-dir "$repo_dir"/.git --work-tree "$repo_dir" diff --quiet
echo (omf::em)"Stashing your changes:"(omf::off)
command git -C "$repo_dir" status --short --untracked-files
command git -C "$repo_dir" stash save --include-untracked --quiet
set stashed true
end
if test "$initial_branch" != master
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 --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 --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 -C "$repo_dir" stash pop
end
if test "$initial_branch" != master
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" checkout $initial_branch --quiet
end
if test "$stashed" = true
command git -C "$repo_dir" stash pop --quiet
echo (omf::em)"Restored your changes:"(omf::off)
command git -C "$repo_dir" status --short --untracked-files
end
return 0
end