From e1e49ceaff3dcc77ea5a9c40a8007c196f5108f0 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Wed, 24 Feb 2016 23:59:55 +0900 Subject: [PATCH] Update is now true to its word :rage1: The update mechanism updates master only. If you are working in branch foo, the branch name is saved and restored later. First attempt a naive git pull --rebase origin master, and if that fails, abort the rebase, fetch origin master, reset to head and clean directory. --- functions/__fisher_path_update.fish | 20 +++++++++++++++++++- test/path-update.fish | 18 ++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/functions/__fisher_path_update.fish b/functions/__fisher_path_update.fish index 70308ff..e60eecb 100644 --- a/functions/__fisher_path_update.fish +++ b/functions/__fisher_path_update.fish @@ -1,10 +1,28 @@ function __fisher_path_update -a path pushd $path + set -l branch + + if not set branch (sed "s|.*/||" < .git/HEAD) + return 1 + end + git checkout master --quiet + git stash --quiet ^ /dev/null - git pull --rebase origin master --quiet + + if not git pull --rebase origin master --quiet ^ /dev/null + git rebase --abort + git fetch origin master --quiet + git reset --hard FETCH_HEAD --quiet + git clean -d --force --quiet + end + git stash apply --quiet ^ /dev/null + if test ! -z "$branch" + git checkout "$branch" --quiet + end + popd end diff --git a/test/path-update.fish b/test/path-update.fish index a0ed544..3dfe5e1 100644 --- a/test/path-update.fish +++ b/test/path-update.fish @@ -1,26 +1,12 @@ set -g path $DIRNAME/.t-$TESTNAME-(random) function -S setup - mkdir -p $path/foo - - function git - 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 $path/foo) +test "$TESTNAME - Update Git repo at path" + -z "" end