summaryrefslogtreecommitdiff
path: root/deploy/buildbot/worker/backup-uncommitted.sh
blob: c6486789f0c36e27ded8e2f073fbb43b289bcbf6 (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
36
37
38
39
40
41
42
#!/bin/sh
# Back up uncommitted work in this tree before anything runs a `clean` checkout.
#
# WHY THIS EXISTS
# master.cfg's checkout step is:
#     steps.Git(repourl=REPO, mode='full', method='clean')
# and buildbot runs the build INSIDE this working tree
# (buildbot-worker puts its builddir under $BUILDWORKER_WORKDIR = /worker).
# So every build silently reverts any uncommitted change here. This bit us
# once: a finished PieMenu edit was discarded by a build and had to be
# reconstructed by hand.
#
# Run this before `./gradlew`, before pushing, and before any build you did
# not initiate yourself. It is cheap and it is the only copy.
set -e
TREE=${1:-/ROM/worker/kukuri-build/build}
STAMP=$(date +%Y%m%d-%H%M%S)
OUT=/ROM/worker-cache/uncommitted-$STAMP.patch

cd "$TREE"
if git diff --quiet && git diff --cached --quiet; then
  echo "clean - nothing to back up"
  exit 0
fi

mkdir -p "$(dirname "$OUT")"
{
  echo "# uncommitted work captured $(date -Iseconds) from $TREE"
  echo "# HEAD was $(git rev-parse --short HEAD) $(git log -1 --format=%s)"
  echo
  git diff
  echo
  echo "# --- staged ---"
  git diff --cached
} > "$OUT"

STAGED=$(git diff --cached --name-only | tr '\n' ' ')
UNSTAGED=$(git diff --name-only | tr '\n' ' ')
echo "backed up to $OUT"
echo "  staged:   ${STAGED:-none}"
echo "  unstaged: ${UNSTAGED:-none}"
wc -l "$OUT"