forked from Oakleon/git-join-repos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-join-repos
executable file
·75 lines (58 loc) · 1.81 KB
/
git-join-repos
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
#!/usr/bin/env bash
set -e
IFS=$'\n\t'
self_name="$(basename $0)"
sed="sed"
if [ -z "$1" ]; then
echo "usage: $self_name filename (where filename is in format \"name url(\n)name url\")"
exit 99
fi
if [ "$(uname -s)" = "Darwin" ]; then
if [ -z "$(which ssed)" ]; then
echo "OS X detected, please ensure you have gnu sed installed. The built-in sed will not work."
echo "To workaround this run \"brew install ssed\""
echo "Obviously, homebrew is required for that to work"
exit 99;
fi
sed="ssed"
fi
data_file="$1"
name_urls="$(cat $data_file)"
repo_name=
repo_url=
function empty_repo_or_die {
total="$(git count-objects -v | cut -d' ' -f2 | awk '{s+=$1}END{print s}')"
if [ "$total" -ne "0" ]; then
echo "This must be run in an empty git repository!"
exit 98
fi
}
function split_line {
repo_name="${a% *}"
repo_url="${a#* }"
}
function repo_master_to_subdir {
git filter-branch -f --index-filter \
"git ls-files -s | ${sed} \"s|\t\\\"*|&${repo_name}/|\" |
GIT_INDEX_FILE=\$GIT_INDEX_FILE.new git update-index --index-info &&
mv \"\$GIT_INDEX_FILE.new\" \"\$GIT_INDEX_FILE\"" HEAD
git filter-branch -f --msg-filter "/bin/echo -n \"${repo_name}: \" && cat"
}
empty_repo_or_die
for a in $name_urls; do
split_line "$a"
git checkout --orphan "$repo_name"
git rm -qrf --ignore-unmatch .
git remote add "$repo_name" "$repo_url"
git fetch "$repo_name"
git merge "$repo_name/master"
repo_master_to_subdir
git remote remove "$repo_name"
done
git checkout --orphan master
git rm -qrf --ignore-unmatch .
for a in $name_urls; do
split_line "$a"
git merge --allow-unrelated-histories --ff -m "$repo_name: $self_name monolithic conversion merge" "$repo_name"
git branch -D "$repo_name"
done