tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

git-copy.sh (876B)


      1 #!/usr/bin/env bash
      2 
      3 set -ex
      4 
      5 if [ $# -lt 3 ]; then
      6  echo "Usage: $0 <repo> <branch> <directory>" 1>&2
      7  exit 2
      8 fi
      9 
     10 REPO="$1"
     11 COMMIT="$2"
     12 DIR="$3"
     13 
     14 echo "Copy '$COMMIT' from '$REPO' to '$DIR'"
     15 if [ -f "$DIR"/.git-copy ]; then
     16  CURRENT=$(cat "$DIR"/.git-copy)
     17  if [ $(echo -n "$COMMIT" | wc -c) != "40" ]; then
     18    # On the off chance that $COMMIT is a remote head.
     19    ACTUAL=$(git ls-remote "$REPO" "$COMMIT" | cut -c 1-40 -)
     20  else
     21    ACTUAL="$COMMIT"
     22  fi
     23  if [ "$CURRENT" = "$ACTUAL" ]; then
     24    echo "Up to date."
     25    exit
     26  fi
     27 fi
     28 
     29 rm -rf "$DIR"
     30 git init -q "$DIR"
     31 
     32 RETRIES=3
     33 COUNT=1
     34 while [ $COUNT -lt $RETRIES ]; do
     35  git -C "$DIR" fetch -q --depth=1 "$REPO" "$COMMIT"
     36  if [ $? -eq 0 ]; then
     37    COUNT=0
     38    break
     39  fi
     40  COUNT=$((COUNT+1))
     41 done
     42 
     43 git -C "$DIR" reset -q --hard FETCH_HEAD
     44 git -C "$DIR" rev-parse --verify HEAD > "$DIR"/.git-copy
     45 rm -rf "$DIR"/.git