-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_fetch_all
40 lines (32 loc) · 848 Bytes
/
git_fetch_all
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
#!/bin/bash
# Function to check if a directory is a git repository
is_git_repository() {
[ -d "$1/.git" ]
}
# Function to fetch in all git repositories within a base directory
fetch_in_repositories() {
for dir in "$1"/*; do
if [ -d "$dir" ]; then
if is_git_repository "$dir"; then
echo "Fetching in $dir..."
git -C "$dir" fetch
echo "Completed fetching in $dir"
echo
fi
fi
done
}
# Main function to handle input and start the process
main() {
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <directory>"
exit 1
fi
base_dir="$1"
if [ ! -d "$base_dir" ]; then
echo "Error: $base_dir is not a directory or does not exist."
exit 1
fi
fetch_in_repositories "$base_dir"
}
main "$@"