summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x.local/bin/fetchgit51
1 files changed, 51 insertions, 0 deletions
diff --git a/.local/bin/fetchgit b/.local/bin/fetchgit
index a8be80f..f33a408 100755
--- a/.local/bin/fetchgit
+++ b/.local/bin/fetchgit
@@ -78,4 +78,55 @@ if [ "$#" -gt 0 ]; then
git pull -q --ff-only --autostash origin $CURRENT_BRANCH
done
+else
+ # Current directory invocation
+ if [ $verbose -gt 0 ]; then
+ echo $PWD
+ fi
+ if [ ! -d .git ]; then # If $PWD/.git doesn't exist
+ # then are we in a ".git" dir? jump up one dir
+ if [ ${PWD##*/} = ".git" ]; then
+ cd ..
+ else #Finally, are we at least in a work tree?
+ if [ ! $(git rev-parse --is-inside-work-tree) ]; then
+ echo "Not in a git directory"
+ exit
+ fi
+ fi
+ fi
+
+ rems=$(eval "git remote") # list all remotes
+ len_rems=${#rems}
+ if [ $len_rems -lt 1 ]; then
+ # If the list of remotes is zero, we don't do any remote ops
+ exit 0
+ fi
+
+ CURRENT_BRANCH=$(git symbolic-ref --short HEAD)
+ # There should always be an origin remote if there is at least one remote
+ DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
+
+ git fetch --all --prune --quiet
+ FETCH_FAILED=$?
+
+ git switch --quiet $DEFAULT_BRANCH
+
+ if [ $FETCH_FAILED -ne 0 ]; then
+ # We should almost always be able to connect to origin
+ git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
+ else
+ if git config remote.upstream.url >/dev/null; then
+ git pull -q --ff-only --autostash upstream $DEFAULT_BRANCH
+ git push -q origin $DEFAULT_BRANCH
+ elif git config remote.upstream.tydavis >/dev/null; then
+ git pull -q --ff-only --autostash tydavis $DEFAULT_BRANCH
+ git push -q origin $DEFAULT_BRANCH
+ else
+ git pull -q --ff-only --autostash origin $DEFAULT_BRANCH
+ fi
+ fi
+
+ git switch --quiet $CURRENT_BRANCH
+ # Update current branch if out of date
+ git pull -q --ff-only --autostash origin $CURRENT_BRANCH
fi