This repository has been archived by the owner on Jan 22, 2018. It is now read-only.
forked from RobLoach/core
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsubtree-split
executable file
·148 lines (119 loc) · 2.75 KB
/
subtree-split
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /bin/bash
UPSTREAM_REPOSITORY=http://git.drupal.org/project/drupal.git
UPSTREAM_DIRECTORY=upstream
DOWNSTREAM_REPOSITORY=$(git config --get remote.origin.url)
# Allow overriding the defaults
if [ -r subtree-split.config ]
then
source subtree-split.config
fi
help() {
echo "Maintains a Git subtree split of the Drupal 8 core directory.
Commands:
init Initializes the Drupal core subsplit in the $UPSTREAM_DIRECTORY
directory
fetch Retrieves updates from the upstream repository
push [branch|tag] ID Publishes the Drupal core directory of a branch or tag
identified by ID as a subtree to the downstream repository
help Show this help text
"
}
init() {
if [ -d $UPSTREAM_DIRECTORY ]
then
echo "The upstream repository is already initialized."
return
else
git clone $UPSTREAM_REPOSITORY $UPSTREAM_DIRECTORY
fi
}
fetch() {
if [ ! -d $UPSTREAM_DIRECTORY ]
then
echo "The upstream repository has not been initialized."
return
else
cd $UPSTREAM_DIRECTORY
git fetch
git prune
git gc
cd ..
fi
}
push_branch() {
if [ ! -d $UPSTREAM_DIRECTORY ]
then
echo "The upstream repository has not been initialized."
return
fi
if [ ! $1 ]
then
echo 'Specify the branch to push.'
return;
fi
cd $UPSTREAM_DIRECTORY
git checkout $1
git pull --rebase
git subtree split -P core -b subtree-core-$1
git push $DOWNSTREAM_REPOSITORY subtree-core-$1:$1
# Clean up so that the next push starts from a clean repository.
git checkout $1
git branch -D subtree-core-$1
# The subtree-cache seems to build up over time, so clear it.
# rm -r .git/subtree-cache/*
cd ..
}
push_tag() {
if [ ! -d $UPSTREAM_DIRECTORY ]
then
echo "The upstream repository has not been initialized."
return
fi
if [ ! $1 ]
then
echo 'Specify the tag to push.'
return;
fi
cd $UPSTREAM_DIRECTORY
# Because we want to apply additional commits to a tag, we cannot checkout the
# tag directly.
git checkout `git show-ref --hash $1`
SUBTREE_HASH=`git subtree split -P core`
# Delete the tag so we can recreate it for the subtree.
git tag --delete $1
git tag $1 $SUBTREE_HASH
git push $DOWNSTREAM_REPOSITORY tag $1
# Clean up so that the next push starts from a clean repository.
git tag --delete $1
# The subtree cache seems to build up over time, so clear it.
rm -r .git/subtree-cache/*
cd ..
}
# Perform the requested action.
case "$1" in
init)
init
;;
fetch)
fetch
;;
push)
case "$2" in
branch)
push_branch $3
;;
tag)
push_tag $3
;;
*)
echo "The first argument to push must be 'branch' or 'tag'."
exit;
esac;
;;
help)
help
;;
*)
help
;;
esac