-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-insert-module
More file actions
executable file
·61 lines (50 loc) · 1.1 KB
/
git-insert-module
File metadata and controls
executable file
·61 lines (50 loc) · 1.1 KB
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
#!/bin/bash
# script-wide globals
script="$0"
root="$(readlink -f $(dirname "$script"))"
tmpDir="/tmp/.gim"
# globals set by parseArgs
repo1=""
repo2=""
function moveToDirectory() {
local origin="$1"
local dest="repo1"
# create a copy of repo1
cd $tmpDir
git clone $origin $dest
cd $dest
# make repo1 look like it was always in a directory
git filter-branch --prune-empty --tree-filter "
if [[ ! -e $dest ]]; then
mkdir -p $dest
git ls-tree --name-only \$GIT_COMMIT \
| xargs -I files mv files $dest
fi"
}
function insertModule() {
# create another copy
local origin="$1"
local moduleOrigin="$2"
local moduleBranch="master" # Default
cd $tmpDir
git clone $origin merged
cd merged
git remote add -f repo2 $moduleOrigin
git merge -s ours --no-commit repo2/$moduleBranch
git read-tree --prefix=repo2/ -u repo2/$moduleBranch
git commit -m "Merged repo2"
git pull -s subtree repo2 $moduleBranch
}
function parseArgs() {
local argv="$@"
repo1="$1"
repo2="$2"
}
function main() {
parseArgs $@
mkdir $tmpDir
cd $tmpDir
moveToDirectory $repo1
insertModule repo1 $repo2
}
main $@