forked from imrehg/aur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
executable file
·66 lines (55 loc) · 1.68 KB
/
sync.sh
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
#!/usr/bin/env bash
usage(){
cat << EOF
Usage:
./sync.sh all - Synchronizes all subtrees
./sync.sh <subtree> - Synchronizes a single subtree
./sync.sh - This screen
./sync.sh <anything-else> - This screen
Available subtrees:
$(subtrees | sed 's/^/ /' )
EOF
}
subtrees(){
git log \
| grep git-subtree-dir \
| tr -d ' ' \
| cut -d ":" -f2 \
| sort \
| uniq \
| xargs -I {} bash -c "if [ -d $(git rev-parse --show-toplevel)/{} ] ; then echo {}; fi"
}
sync(){
[ -z "$1" ] && return 1
# The code for the push below could usually be replaced with:
# git subtree push --prefix="$1"
# "ssh+git://[email protected]/$1.git" master
# but we want to push from a different branch to master
# in lieu, of what the above does: master to master.
remote="ssh+git://[email protected]/$1.git"
# current_branch="$(git symbolic-ref --short -q HEAD)"
# split_commit="$(git subtree split --prefix="$1" "${current_branch}")"
# git push "${remote}" "${split_commit}:master" --force
git subtree push --prefix="$1" "${remote}" master
git subtree pull --prefix="$1" "${remote}" master --squash
}
new(){
[ -z "$1" ] && return 1
# remote="ssh+git://[email protected]/$1.git"
# git remote add "$1" "$remote"
current_branch="$(git symbolic-ref --short -q HEAD)"
split_commit="$(git subtree split --prefix="$1" "${current_branch}")"
# git push "$remote" "$(git_current_branch):master"
}
main(){
if [ -z "$1" ]; then
usage
elif [ "$1" = "all" ]; then
subtrees | while read -r subtree ; do sync "${subtree}" ; done
elif [[ "$(subtrees)" =~ $1 ]]; then
sync "$1"
else
usage
fi
}
main "$@"