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.
|
6 | set -e
|
7 |
|
8 | REMOTE="origin"
|
9 |
|
10 |
|
11 | STATE_DIR="$(note config get state_dir)"
|
12 | GIT_DIR="$STATE_DIR/.git"
|
13 | WORK_DIR="$STATE_DIR"
|
14 | GIT="git --git-dir=$GIT_DIR --work-tree=$WORK_DIR"
|
15 |
|
16 | # assume the current branch is desired
|
17 | BRANCH="$($GIT branch --show-current)"
|
18 |
|
19 | $GIT fetch --quiet --all
|
20 |
|
21 | LOCAL_HEAD="$($GIT rev-parse @)"
|
22 | REMOTE_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
|
26 | if [[ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]] ; then
|
27 | $GIT pull --quiet --ff-only "$REMOTE" "$BRANCH"
|
28 | fi
|
29 |
|
30 | $GIT push --quiet "$REMOTE" "$BRANCH"
|