Replace omf.util_sync with omf.repo.pull

Based on
https://github.com/Homebrew/homebrew/blob/master/Library/Homebrew/cmd/update.rb#L175-L221
This commit is contained in:
Bruno Pinto 2015-09-06 01:36:02 +01:00
parent 2a0e5ba7cc
commit af49d6f1c2
4 changed files with 37 additions and 10 deletions

View File

@ -41,7 +41,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.util_sync "origin" >/dev/null ^&1
omf.repo.pull
popd
echo (omf::em)"$name_or_url $install_type up to date."(omf::off)
else

View File

@ -0,0 +1,35 @@
function omf.repo.pull
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
if not command git diff --quiet
echo (omf::em)"Stashing your changes:"(omf::off)
command git status --short --untracked-files
command git stash save --include-untracked --quiet
set stashed true
end
if test "$initial_branch" != master
command git checkout master --quiet
end
# the refspec ensures that 'origin/master' gets updated
command git pull --rebase --quiet origin "refs/heads/master:refs/remotes/origin/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
end
if test "$initial_branch" != master
command git checkout $initial_branch --quiet
end
if test "$stashed" = true
command git stash pop --quiet
echo (omf::em)"Restored your changes:"(omf::off)
command git status --short --untracked-files
end
end

View File

@ -10,7 +10,7 @@ function omf.update
if git pull --rebase $repo master >/dev/null ^&1
git stash apply >/dev/null ^&1
else
omf.util_sync "origin"
omf.repo.sync
end
end
end

View File

@ -1,8 +0,0 @@
function omf.util_sync -a remote
set -l repo $remote
set -q argv[1]; and set repo $argv[1]
git fetch origin master
git reset --hard FETCH_HEAD
git clean -df
end