-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-merge
executable file
·55 lines (45 loc) · 1.43 KB
/
post-merge
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
#!/bin/bash
#
# git-subrepo post-merge hook
#
# Copyright (C) Brecht Machiels <brecht@mos6581.org>
#
debug=
. git-sh-setup
source "$GIT_DIR/hooks/subrepo"
echo "post-merge"
original_commit=$(git rev-parse HEAD)
subdirs=$(read_subrepo_dirs)
index=1
merge_parents=
while true; do
parent=$(git rev-parse --verify --quiet $original_commit^$index)
if [[ $? != 0 ]]; then
break
fi
merge_parents="$merge_parents $parent"
index=$(($index + 1))
done
assert [ $(length $merge_parents) -ge 2 ]
#echo $merge_parents
new_parents=$merge_parents
for subdir in $subdirs; do
subrepo_parents=
for parent in $merge_parents; do
subrepo_parent=$(find_last_subrepo_commit $parent "$subdir")
subrepo_parents="$subrepo_parents $subrepo_parent"
done
assert [ -n "$subrepo_parents" ]
if [ $(length $subrepo_parents) -ge 2 ]; then
subrepo_tree=$(subtree_for_commit $original_commit "$subdir")
subrepo_merge_commit=$(clone_commit $original_commit $subrepo_tree "$subrepo_parents")
else
subrepo_merge_commit=$subrepo_parents
fi
new_parents="$new_parents $subrepo_merge_commit"
done
original_tree=$(toptree_for_commit $original_commit)
main_commit=$(clone_commit $original_commit $original_tree "$new_parents")
git reset --quiet $main_commit
#say "main-line commit $(git rev-parse --short $main_commit) and"
#say "subrepo commit $(git rev-parse --short $subrepo_commit) derived from:"