-
Notifications
You must be signed in to change notification settings - Fork 1
/
spruce.sh
executable file
·73 lines (63 loc) · 2.46 KB
/
spruce.sh
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
#!/bin/bash
# Proof of concept showing that re-rolls can be *fast* without checking out all of core.
ISSUEID=$1
COMMENT_DATE_OF_PATCH=$2
PATCHURL=$3
PATCH=$4
DRUPAL8_REPOSITORY='../Drupal_no_checkout'
# Right now this assumes that I have a repository checked out
# Under ../Drupal_no_checkout created with:
# git clone http://git.drupal.org/project/drupal.git -n Drupal_no_checkout
# TODO: Take in arguments/Make it loop.
# The -s options create a shared clone of the local repo
# (it uses symlinks to the original .git in DRUPAL8_REPOSITORY
# This is much faster and saves disk space.
# The -n prevents the clone from checking out a working directory
echo "cloning"
git clone -n -s -q ${DRUPAL8_REPOSITORY} issue_${ISSUEID}
cd issue_${ISSUEID}
wget https://drupal.org/files${PATCHURL}
# This reads the patch and checks out *only the files that have changed*
# ignoring newly added files
lsdiff --strip=1 -s ${PATCH} |awk '!/^\+/ {print $2}' |xargs git checkout HEAD
echo "applying patch"
git apply ${PATCH}
if [ $? -ne 0 ]; then
echo "git apply FAILED"
echo "Sparse Checkout"
# This does a 'sparse checkout' which configures the repository to think
# That it is only tracking the changed files
git config core.sparsecheckout true
lsdiff --strip=1 -s ${PATCH} |awk '{print $2}' >> .git/info/sparse-checkout
git read-tree -m -u HEAD
# This gets the commit ID of when the patch last applied *and passed tests*
COMMITID=`git log --before="${COMMENT_DATE_OF_PATCH}" -1 --pretty=format:%H`
# Reset our mini repo to that commit id, reapply the patch, and rebase onto origin/HEAD
echo "git reset"
git reset -q ${COMMITID}
echo "git create branch"
git checkout -q -b issue-${ISSUEID}
echo "git checkout the files"
lsdiff --strip=1 -s $PATCH |awk '!/^\+/ {print $2}' |xargs git checkout --
echo "applying patch,again"
git apply ${PATCH}
echo "adding files to the commit"
lsdiff --strip=1 ${PATCH} |xargs git add -A
echo "commiting"
git commit -m "${PATCH} applied"
git rebase origin/HEAD
if [ $? -ne 0 ]; then
echo "RESULT: Automatic rebase failed - merge conflicts happened - use \'git mergetool\' to fix"
cd ..
mv issue_${ISSUEID} issue_${ISSUEID}_failed
else
echo "RESULT: Automatic rebase success!"
git show HEAD > ${PATCH}_new
cd ..
mv issue_${ISSUEID} issue_${ISSUEID}_rebased
fi
else
echo "RESULT: git apply Success - Patch Still Applies against current HEAD for ${ISSUEID}"
cd ..
mv issue_${ISSUEID} issue_${ISSUEID}_applies
fi