summaryrefslogtreecommitdiff
path: root/misc/merge-ioq3-into-trem.sh
blob: c943a03ef6158d915974f99673d7122f9f692815 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /bin/bash
# TODO Consider rewrite in perl/python to make this a bit less crappy

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PATCHES_DIR=${DIR}/patches
LAST_REVISION_FILE=${DIR}/last-merged-ioq3-revision
LAST_REVISION=`cat ${LAST_REVISION_FILE}`

set -f
# Things that exist in ioq3 which we don't want
EXCLUSIONS="BUGS ChangeLog README ./*.txt
  NOTTODO TODO misc/* *.mak src/cgame/*
  src/game/* src/ui/* src/q3_ui/* src/botlib/* ui/*"

EXCLUDE_PARAMETERS=""
for EXCLUSION in ${EXCLUSIONS}
do
  EXCLUDE_PARAMETERS+="--exclude=${EXCLUSION} "
done

set +f

PATCHES=`ls ${PATCHES_DIR}/*.patch 2> /dev/null`
if [ -z "${PATCHES}" ]
then
  echo "Fetching and generating patches..."
  git fetch https://github.com/ioquake/ioq3.git

  mkdir -p ${PATCHES_DIR}
  git format-patch -o ${PATCHES_DIR} ${LAST_REVISION}..FETCH_HEAD
fi

if [ -d ".git/rebase-apply" ]
then
  echo "Failed patch detected."

  git diff --quiet --exit-code
  if [ "$?" -ne 0 ]
  then
    echo "Unstaged changes present; git add any that are pending:"
    git status
    exit 1
  fi

  PATCH=`ls ${PATCHES_DIR}/*.patch | head -n 1`
  SHA=`cat ${PATCH} | head -n 1 | awk '{print $2;}'`
  echo "Processing ${SHA} ${PATCH}..."

  DIFF=`git diff --cached`
  if [ -z "${DIFF}" ]
  then
    echo "Patch does nothing; skipping."
    read -p "Confirm skip? "
    git am --skip
  else
    read -p "Confirm resolve? "
    git am --resolved
  fi

  if [ "$?" -ne 0 ]
  then
    echo "Patch failed to apply."
    exit $?
  fi

  echo ${SHA} > ${LAST_REVISION_FILE}
  rm ${PATCH}
fi

PATCHES=`ls ${PATCHES_DIR}/*.patch 2> /dev/null`
if [ -n "${PATCHES}" ]
then
  for PATCH in ${PATCHES}
  do
    SHA=`cat ${PATCH} | head -n 1 | awk '{print $2;}'`
    echo "Processing ${SHA} ${PATCH}..."
    cat ${PATCH} | sed -e 's/\([ab]\)\/code\//\1\/src\//g' | \
      git am ${EXCLUDE_PARAMETERS} --quiet --3way

    if [ "$?" -ne 0 ]
    then
      echo "Patch failed to apply."
      git status
      exit $?
    fi

    echo ${SHA} > ${LAST_REVISION_FILE}
    rm ${PATCH}
  done
else
  echo "Nothing to do."
fi