-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_git_utility.sh
More file actions
60 lines (50 loc) · 1.56 KB
/
Copy pathmulti_git_utility.sh
File metadata and controls
60 lines (50 loc) · 1.56 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
55
56
57
58
59
60
#!/bin/bash
repositories=(
"https://github.com/user/repo-1.git"
"https://github.com/user/repo-2.git"
)
operate_on_repo() {
local repo_path="$1"
local operation="$2" # pull / stash / abort
cd "$repo_path" || exit
case "$operation" in
"pull")
git pull origin "$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
;;
"stash")
git stash
;;
"abort")
git reset --hard HEAD
git clean -df
git checkout "$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
git pull origin "$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')"
;;
*)
echo "Invalid operation"
;;
esac
cd ..
}
update_repositories() {
local operation="$1" # pull / stash / abort
for repo_url in "${repositories[@]}"; do
repo_name=$(basename "$repo_url" .git)
if [ ! -d "$repo_name" ]; then
# Clone the repository if it doesn't exist
git clone "$repo_url"
echo "Cloned $repo_name"
else
echo "Repository $repo_name already exists"
fi
operate_on_repo "$repo_name" "$operation"
done
}
# Determine the operation based on the argument
if [ "$1" == "--skip" ]; then
update_repositories "abort"
elif [ "$1" == "--stash" ]; then
update_repositories "stash"
else
update_repositories "pull"
fi