-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitpullall.sh
More file actions
executable file
·65 lines (57 loc) · 2.07 KB
/
gitpullall.sh
File metadata and controls
executable file
·65 lines (57 loc) · 2.07 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
61
62
63
64
65
#!/usr/bin/env bash
# Purpose: Pull all changes from all repositories. This script is usefull in order to get all latest changes in main or master in your local repositories.
set -e
ORGANIZATION=`cat cloneallrepos.sh | grep ^ORGANIZATION= | cut -d= -f2 | xargs`
PROJECT=`cat cloneallrepos.sh | grep ^PROJECT= | cut -d= -f2 | xargs`
PAT=`cat cloneallrepos.sh | grep ^PAT= | cut -d= -f2 | xargs`
while getopts "o:p:a:h" opt ; do
case $opt in
o)
ORGANIZATION=${OPTARG}
;;
p)
PROJECT=${OPTARG}
;;
a)
PAT=${OPTARG}
;;
:)
echo "Error: Option -$OPTARG requires an argument."
exit 1
;;
*)
echo "Usage: $0 -o <organization> -p <project> -a <PAT token> [-h]"
echo "-o : The Azure DevOps organization name"
echo "-p : The project name"
echo "-a : The PAT token to use"
echo "-h : Please send help"
exit 0
;;
esac
done
# Check if all required variables are set
if [ -z "$ORGANIZATION" ] || [ -z "$PROJECT" ] || [ -z "$PAT" ]; then
echo "Error: All parameters -o, -p, and -a are required."
exit 1
fi
# Revert to the main branch, get all data and remove all remote branches
for d in */; do
# Check if the repository is disabled in the azure devops api
# Query the azure devops api to check if the repository is disabled
repoapiurl="https://dev.azure.com/$ORGANIZATION/${PROJECT// /%20}/_apis/git/repositories/$d?api-version=7.1-preview.1"
# Check if the repository is disabled
status_code=$(curl --http1.1 --output /dev/null --silent --write-out "%{http_code}" \
--url "$repoapiurl" -u ":$PAT" --header "Accept: application/json")
if [ "$status_code" -ne 200 ]; then
echo "Repository $d is disabled or does not exist, skipping it."
continue
fi
echo $d
# If the directory doesn't end with .wiki, then continue
git -C $d config pull.rebase false
if [[ "$d" != *.wiki/ ]]; then
git -C $d checkout main || git -C $d checkout master
fi
git -C $d fetch --prune
git -C $d pull
done