-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgitr
executable file
·63 lines (51 loc) · 1.23 KB
/
gitr
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
#!/bin/sh
# Exit on error
set -o errexit
usage() {
echo """
recursive git
Runs the given Git command recursively in all the Git repositories located under
the current directory.
Usage:
$ cd ~/version/project-group
$ $0 GIT-COMMAND
Examples:
$ $0 status
$ $0 pull
$ $0 add package.json
$ $0 commit
$ $0 push
""" 1>&2
}
checkArgs() {
if [ $# -lt 1 ]; then
usage; exit 3
fi
}
checkArgs "$@"
# Store current working directory
cwd=$(pwd)
# RED=$(tput setaf 1)
# GREEN=$(tput setaf 2)
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
# find won't descend into .git directories, but it still does descend into git
# repositories, looking for other .git folders. And that could be a costly
# operation.
for dotgit_dir_path in $(find . -name .git -type d -prune)
do
# Restore current working directory for successive runs
cd "$cwd"
# Change to the Git repository directory
cd "$dotgit_dir_path/.."
printf "\n"
printf "%s" "$BOLD"
printf "%s" "$(pwd)"
printf "%s" "$NORMAL"
printf " ← git %s" "$*"
printf "\n"
# Some commands like "git grep" returns with a non-zero status when nothing
# is found, thus the "|| true" to ensure the line is always a success.
git "$@" || true
printf "\n"
done