summaryrefslogtreecommitdiff
path: root/bin/git-dotfiles-rebase
blob: b7018a1f2b7c96d211985ad415d1c0a384e5b075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh

. $HOME/.shenv

set -e

sign () {
    if ! git is-clean; then
	echo >&2 "$0: cannot -S --amend commit: dotfiles working tree not clean"
	exit 1
    fi
    branch=$(git rev-parse --abbrev-ref HEAD)
    [ "$branch" = "master" ] || git checkout master
    git commit -S --amend --no-edit
    if [ "$branch" != "master" ]; then
	git checkout "$branch"
	git rebase master
    fi
}

cd $HOME/src/dotfiles
hostname="$(hostname)"          # use '-s' ?
if git rev-parse refs/heads/$hostname >/dev/null 2>&1; then
    git checkout $hostname
    git rebase master
    if ! git push origin master +$hostname; then
        sign
        git push origin master +$hostname
    fi
else
    if ! git push origin master; then
        sign
        git push origin master
    fi
fi