-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgfp.sh
More file actions
executable file
·54 lines (44 loc) · 1.34 KB
/
gfp.sh
File metadata and controls
executable file
·54 lines (44 loc) · 1.34 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
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# GFP -> git fetch prune
# Script to run git fetch --prune on all git repositories in subdirectories
# Function to check if a directory is a git repository
is_git_repo() {
[ -d "$1/.git" ]
}
# Function to run git fetch --prune in a directory
fetch_and_prune() {
local dir="$1"
echo "Processing: $dir"
if cd "$dir"; then
if git fetch --prune; then
echo "✅ Successfully fetched and pruned: $dir"
else
echo "❌ Failed to fetch and prune: $dir"
fi
cd - > /dev/null
else
echo "❌ Could not enter directory: $dir"
fi
echo ""
}
# Main script
main() {
local base_dir="${1:-.}" # Use current directory if no argument provided
if [ ! -d "$base_dir" ]; then
echo "Error: Directory '$base_dir' does not exist"
exit 1
fi
echo "Searching for git repositories in: $(realpath "$base_dir")"
echo "----------------------------------------"
# Find all subdirectories and check if they're git repos
find "$base_dir" -maxdepth 1 -type d -not -path "$base_dir" | while read -r dir; do
if is_git_repo "$dir"; then
fetch_and_prune "$dir"
else
echo "Skipping (not a git repo): $dir"
fi
done
echo "Done!"
}
# Run the main function with all arguments
main "$@"