This repository has been archived by the owner on Dec 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
git-find-fetch
executable file
·73 lines (64 loc) · 1.95 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
#!/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
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
echo git svn fetch: $repo_dir
GIT_DIR="$repo_dir" git svn fetch
# If this is a gc-utils repo, use gc-utils update
elif grep -q '^\[gc-utils\]' "$repo_dir"/config
then
echo gc-utils update: $repo_dir
(cd "$repo_dir"; gc-utils update)
fi
GIT_DIR="$repo_dir" git remote update
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
if [[ $repack == true ]]; then
GIT_DIR="$repo_dir" git fsck --full && \
GIT_DIR="$repo_dir" git repack -a -d -f --window=200 --depth=50 && \
GIT_DIR="$repo_dir" git prune
fi
fi
done