bashcontrib/note-on-sync -rwxr-xr-x 855 B
1#!/bin/bash
2# This is an example script that will synchronize a git repository that is
3# presumed to be the state_dir of a note directory. It will initially check
4# to see if changes exist remotely and try to rebase them onto the current
5# HEAD.
6set -e
7
8REMOTE="origin"
9
10
11STATE_DIR="$(note config get state_dir)"
12GIT_DIR="$STATE_DIR/.git"
13WORK_DIR="$STATE_DIR"
14GIT="git --git-dir=$GIT_DIR --work-tree=$WORK_DIR"
15
16# assume the current branch is desired
17BRANCH="$($GIT branch --show-current)"
18
19$GIT fetch --quiet --all
20
21LOCAL_HEAD="$($GIT rev-parse @)"
22REMOTE_HEAD="$($GIT rev-parse $REMOTE/$BRANCH)"
23
24# check if remote and local head are out of sync, if they are then pull down
25# changes with --rebase --interactive
26if [[ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]] ; then
27 $GIT pull --quiet --ff-only "$REMOTE" "$BRANCH"
28fi
29
30$GIT push --quiet "$REMOTE" "$BRANCH"