Skip to content

Commit

Permalink
Add self updating feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ctubbsii committed Nov 3, 2020
1 parent 38cb886 commit 9703a9d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions git-sync
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# git-sync
# https://github.com/ctubbsii/git-sync
GIT_SYNC_VERSION='1.2.1'
GIT_SYNC_VERSION='1.3.0'

# catch most errors
set -eE
Expand Down Expand Up @@ -60,7 +60,7 @@ function isVerbose() { [[ $GIT_SYNC_VERBOSE -ge 1 ]] || return 1; }
function isVVerbose() { [[ $GIT_SYNC_VERBOSE -ge 2 ]] || return 1; }
function logVerbose() { if isVerbose; then log "$@"; fi }
function logVVerbose() { if isVVerbose; then log "$@"; fi }
function usage() { log 'Usage: git sync [-V | --version | -v | --verbose | -vv | --very-verbose]'; }
function usage() { log 'Usage: git sync [self] [-V | --version | -v | --verbose | -vv | --very-verbose]'; }

# get the remote tracking branch information, given a local branch name
function remoteBranch() {
Expand Down Expand Up @@ -144,6 +144,19 @@ function worktreeBranch() {

function git_sync_main() {
local worktrees w b
if [[ ${#@} -eq 1 || ${#@} -eq 2 ]] && [[ $1 == "self" && -z $GIT_SYNC_IN_SELF_LOOP ]]; then
GIT_SYNC_IN_SELF_LOOP=1
shift
cd "$(dirname "$(readlink -f "$0")")" || return 1
if git rev-parse --git-dir &>/dev/null; then
git_sync_main "$@" || return 1
return 0
else
echo "Syncing $(green self) not supported outside git worktree ($(red "$(relDir "$(pwd)")"))"
return 0
fi
fi

if [[ ${#@} -ge 2 ]]; then usage && return 1
elif [[ ${#@} -eq 1 ]]; then
case "$1" in
Expand All @@ -154,6 +167,10 @@ function git_sync_main() {
esac
fi

if [[ -n $GIT_SYNC_IN_SELF_LOOP ]]; then
echo "Syncing $(green self) ($(yellow "$(relDir "$(pwd)")")) ..."
fi

# fetch from remotes
logVerbose ": $(yellow Updating) $(green remotes) ..."
if isVerbose; then
Expand Down

0 comments on commit 9703a9d

Please sign in to comment.