-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-batch
More file actions
executable file
·43 lines (41 loc) · 1.24 KB
/
Copy pathgit-batch
File metadata and controls
executable file
·43 lines (41 loc) · 1.24 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
#! /bin/sh
#
# git-batch: Iterate git commands over immediate sub-directories
# set GIT_BATCH_STDERR to stderr (or stdout) to show errors from git
if [ $# -eq 0 ]; then
script=`basename $0`
echo "Usage: $script [OPTION] COMMAND [FILE]"
echo "Iterate git commands over immediate sub-directories"
echo
echo " -f, --force Force using all args as a git command params"
echo
echo "Examples:"
echo " $script status Show status for all repos"
echo " $script -f fetch upstream Fetch from remote 'upstream' for all repos"
echo " $script pull origin Pull from remote 'origin' for all repos, limit to repos listed in file 'origin' if it exists"
else
if [ "$1" = '-f' ] || [ "$1" = '--force' ]; then
shift
unset remote
else
# loop over $@; store first arg that exists as a file in $remote
for remote; do
if [ -f "$remote" ]; then break; fi
done
fi
if [ -n "$remote" ] && [ -f "$remote" ]; then
grep -v '^#' "$remote" | while read dir
do
[ ! -d "$dir" ] && continue
cd "$dir"
if [ $? -eq 0 ]; then
echo
pwd
git $* 2>/dev/${GIT_BATCH_STDERR:-null}
cd ..
fi
done
else
find -maxdepth 1 -type d -exec sh -c "cd '{}' && echo && pwd && git $* 2>/dev/${GIT_BATCH_STDERR:-null}" \;
fi
fi