forked from jwiegley/git-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-find-fetch
executable file
·101 lines (87 loc) · 2.83 KB
/
git-find-fetch
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
#!/bin/bash
# usage: git-find-fetch [--mirror] [--repack] DIRS...
#
# by John Wiegley <[email protected]>
#
# The purpose of this script is to walk recursively through a set of
# directories, fetching updates for any and all Git repositories found
# therein.
#
# The script is smart about using git-svn or gc-utils, if those are needed to
# get updates. Further, it calls "git remote update" for each repository, to
# ensure all its remotes are also updated.
#
# Lastly, if you have a remote called "mirror" in any repository, all its refs
# will be "push --mirror"'d to that remote under the assumption that you want
# the mirror to receive all the updates you just fetch'd.
#
# Options:
#
# --mirror Only push to your mirrors, do not fetch.
# --repack Repack and prune repositories after updating them.
mirror_only=false
if [[ "$1" == --mirror ]]; then
mirror_only=true
shift 1
fi
repack=false
if [[ "$1" == --repack ]]; then
repack=true
shift 1
fi
find "$@" \( -name .git -o -name '*.git' \) -type d | \
while read repo_dir
do
if [[ ! -f "$repo_dir"/config ]]; then
continue
fi
if [[ -f "$repo_dir"/../fetch.sh ]]; then
(cd "$repo_dir"/..; sh fetch.sh)
continue
fi
if [[ $mirror_only == false ]]; then
# If this is a git-svn repo, use git svn fetch
if grep -q '^\[svn-remote ' "$repo_dir"/config
then
if [[ -d "$repo_dir"/svn ]]; then
echo git svn fetch: $repo_dir
GIT_DIR="$repo_dir" git svn fetch
fi
# If this is a gc-utils repo, use gc-utils update
elif grep -q '^\[gc-utils\]' "$repo_dir"/config
then
echo gc-update: $repo_dir
(cd "$repo_dir"; gc-update)
fi
echo $repo_dir
GIT_DIR="$repo_dir" git remote update
fi
HG_DIR="$repo_dir"/../.git-hg
FAST_EXPORT=$HOME/src/fast-export/hg-fast-export.sh
if [[ -d "$HG_DIR" ]]; then
(cd "$HG_DIR"; hg pull && hg update)
(cd "$repo_dir"/..; PYTHON=python2.6 sh $FAST_EXPORT -r .git-hg)
fi
BZR_DIR="$repo_dir"/../.git-bzr
if [[ -d "$BZR_DIR" ]]; then
(cd "$BZR_DIR"; bzr pull)
(cd "$repo_dir"/..; git bzr fetch upstream | cat)
fi
DARCS_DIR="$repo_dir"/../.git-darcs
GIT_DARCS_IMPORT=$HOME/bin/git-darcs-import
if [[ -d "$DARCS_DIR" && -f "$GIT_DARCS_IMPORT" ]]; then
(cd "$DARCS_DIR"; darcs pull)
(cd "$repo_dir"/..; $GIT_DARCS_IMPORT .git-darcs)
(cd "$repo_dir"; git rebase git-darcs-import)
fi
if [[ $repack == true ]]; then
GIT_DIR="$repo_dir" git flush
fi
for remote in $(GIT_DIR="$repo_dir" git remote)
do
if [[ $remote == mirror ]]; then
echo git push: $repo_dir -- $remote
GIT_DIR="$repo_dir" git push -f --mirror $remote
fi
done
done