summaryrefslogtreecommitdiff
path: root/bin/git-dotfiles-rebase
blob: 5f96244a45ed059c30602c2444723807a88bd0fb (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
#!/bin/sh

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