2015-09-06 08:36:02 +08:00
|
|
|
function omf.repo.pull
|
2015-09-18 01:39:15 +08:00
|
|
|
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
|
2015-09-21 23:57:17 +08:00
|
|
|
set -l repo_dir $argv[1]
|
2015-09-18 01:39:15 +08:00
|
|
|
|
2015-09-21 23:57:17 +08:00
|
|
|
if test (command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" config --get remote.upstream.url)
|
2015-09-06 09:04:45 +08:00
|
|
|
set repository upstream
|
|
|
|
else
|
|
|
|
set repository origin
|
|
|
|
end
|
|
|
|
|
2015-09-21 23:57:17 +08:00
|
|
|
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
|
2015-09-06 08:36:02 +08:00
|
|
|
|
2015-09-21 23:57:17 +08:00
|
|
|
if not command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" diff --quiet
|
2015-09-06 08:36:02 +08:00
|
|
|
echo (omf::em)"Stashing your changes:"(omf::off)
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" status --short --untracked-files
|
2015-09-06 08:36:02 +08:00
|
|
|
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" stash save --include-untracked --quiet
|
2015-09-06 08:36:02 +08:00
|
|
|
set stashed true
|
|
|
|
end
|
|
|
|
|
|
|
|
if test "$initial_branch" != master
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" checkout master --quiet
|
2015-09-06 08:36:02 +08:00
|
|
|
end
|
|
|
|
|
2015-09-06 09:04:45 +08:00
|
|
|
# the refspec ensures that '$repository/master' gets updated
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" pull --rebase --quiet $repository "refs/heads/master:refs/remotes/$repository/master"
|
2015-09-06 08:36:02 +08:00
|
|
|
if test $status -eq 2 #SIGINT
|
2015-09-21 23:57:17 +08:00
|
|
|
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
|
2015-09-06 08:36:02 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if test "$initial_branch" != master
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" checkout $initial_branch --quiet
|
2015-09-06 08:36:02 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if test "$stashed" = true
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" stash pop --quiet
|
2015-09-06 08:36:02 +08:00
|
|
|
|
|
|
|
echo (omf::em)"Restored your changes:"(omf::off)
|
2015-09-21 23:57:17 +08:00
|
|
|
command git --git-dir "$repo_dir"/.git --work-tree "$repo_dir" status --short --untracked-files
|
2015-09-06 08:36:02 +08:00
|
|
|
end
|
2015-09-06 09:04:45 +08:00
|
|
|
|
|
|
|
return 0
|
2015-09-06 08:36:02 +08:00
|
|
|
end
|