-
Notifications
You must be signed in to change notification settings - Fork 7
/
autosplit
executable file
·141 lines (135 loc) · 3.92 KB
/
autosplit
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
#!/bin/sh
#
# Copyright (c) 2007 Andy Parkins
# Copyright (c) 2012 The Horde Project
#
# This hook will automatically split the base horde repository into
# separate modules and push those into separate repositories on
# github. "git subtree" is the command that the script uses to execute
# the module split.
#
# The approach is slightly complicated as pushing to the remote
# repository expects the remote to be a bare repository. At the same
# time "git subtree" requires a local checkout to work correctly. In
# addition the "git subtree split --rejoin" operations adds marker
# merges that may not end up in the main branch - otherwise we won't
# be able to push to it anymore.
#
# As a result the script:
#
# 1) Marks the repo as non-bare so that subtree will be able to work.
#
# 2) Switches to the branch that has been pushed to. This allows subtree
# to work on the splitted subtree in the checkout.
#
# 3) Resets to HEAD for this branch so that the subtree to be splitted
# is ensured to be present.
#
# 4) Potentially creates a new branch that will receive the subtree
# marker merges - only if that branch does not exist yet.
#
# 5) Switches to this subtree specific branch and executes the
# split. The split will "--rejoin" the splitted branch onto the
# current branch. The splitted code will end up in a module and
# branch specific branch.
#
# 6) Pushes the splitted branch to the module specific repository on
# github.
#
# 7) Reverts back to a bare repository so that it can be used for
# pushing again.
#
autosplit()
{
# --- Arguments
oldrev=$(git rev-parse $1)
newrev=$(git rev-parse $2)
refname="$3"
# --- Interpret
# 0000->1234 (create)
# 1234->2345 (update)
# 2345->0000 (delete)
if expr "$oldrev" : '0*$' >/dev/null
then
change_type="create"
else
if expr "$newrev" : '0*$' >/dev/null
then
change_type="delete"
else
change_type="update"
fi
fi
# --- Get the revision types
newrev_type=$(git cat-file -t $newrev 2> /dev/null)
oldrev_type=$(git cat-file -t "$oldrev" 2> /dev/null)
case "$change_type" in
create|update)
rev="$newrev"
rev_type="$newrev_type"
;;
delete)
rev="$oldrev"
rev_type="$oldrev_type"
;;
esac
# The revision type tells us what type the commit is, combined with
# the location of the ref we can decide between
# - working branch
# - tracking branch
# - unannoted tag
# - annotated tag
case "$refname","$rev_type" in
refs/heads/*,commit)
# branch
refname_type="branch"
short_refname=${refname##refs/heads/}
echo >&2 "*** Handling combination ($rev_type, $refname)."
;;
refs/tags/*,commit)
echo >&2 "*** Ignoring combination ($rev_type, $refname)."
exit 0
;;
refs/tags/*,tag)
echo >&2 "*** Ignoring combination ($rev_type, $refname)."
exit 0
;;
refs/remotes/*,commit)
echo >&2 "*** Ignoring combination ($rev_type, $refname)."
exit 0
;;
*)
# Anything else (is there anything else?)
echo >&2 "*** Unknown type of update to $refname ($rev_type)"
exit 1
;;
esac
subtrees="framework/Translation"
for subtree in $subtrees;
do
case "$subtree" in
framework/*)
module=Horde_${subtree##framework/}
;;
*)
module=$subtree
;;
esac
git config --bool core.bare false
git checkout $short_refname
git reset --hard HEAD
if [ -z "`git branch | grep subtrees/$short_refname`" ]; then
git branch subtrees/$short_refname
fi
git checkout subtrees/$short_refname
git merge $short_refname
git subtree split f6f896c195d49b.. --prefix=$subtree --annotate="(horde) " --branch subtrees/$module/$short_refname --rejoin
git push git@github.com:wrobel/$module.git subtrees/$module/$short_refname:$short_refname
git config --bool core.bare true
done
}
#while read oldrev newrev refname
#do
# Currently deactivated until this approach has been discussed and shown to be working
#autosplit $oldrev $newrev $refname
#done