summaryrefslogtreecommitdiff
path: root/fuzz/config/git-copy.sh
blob: 2e57a6999ea27f3fb2065e94e7f795df319dec06 (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
#!/usr/bin/env bash

set -ex

if [ $# -lt 3 ]; then
  echo "Usage: $0 <repo> <branch> <directory>" 1>&2
  exit 2
fi

REPO="$1"
COMMIT="$2"
DIR="$3"

echo "Copy '$COMMIT' from '$REPO' to '$DIR'"
ACTUAL=$(git ls-remote "$REPO" "$COMMIT" | cut -c 1-40 -)
if [ -z "$ACTUAL" ]; then
  # Use this directly on the hope that it works.
  ACTUAL="$COMMIT"
fi
echo "Using commit hash '$ACTUAL'"
if [ -f "$DIR"/.git-copy ]; then
  CURRENT=$(cat "$DIR"/.git-copy)
  if [ "$CURRENT" = "$ACTUAL" ]; then
    echo "Up to date."
    exit
  fi
fi

rm -rf "$DIR"
git init -q "$DIR"
git -C "$DIR" fetch -q --depth=1 "$REPO" "$ACTUAL"
git -C "$DIR" checkout "$ACTUAL"
git -C "$DIR" rev-parse --verify HEAD > "$DIR"/.git-copy
rm -rf "$DIR"/.git