blob: ba6cacb0845d79044a8d275713fffbfea174cf5e (
plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/bin/sh
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#
# This script deletes the branch given as parameter from origin for
# all submodules.
#
# The script is intented to be used to clean out old release
# branches from Gerrit. If a branch head doesn't match the release
# tag, deleting is skipped.
#
# Run the script in a qt5 project.
#
root_dir=$(pwd)
parameters_valid="true"
if ! [ -e "./.git" ]; then
echo "Not in a git directory"
parameters_valid="false"
fi
if [ -z "$1" ]; then
echo "Branch parameter missing"
parameters_valid="false"
fi
if [ -z "$2" ]; then
echo "Release tag parameter missing"
parameters_valid="false"
fi
if [ "$parameters_valid" == "false" ]; then
echo "Usage: ./delete_remote_branches.sh <branch_name> <release_tag>"
exit
fi
echo "Searching for remote branch..."
if ! git ls-remote --exit-code origin "refs/heads/$1"; then
echo "Remote branch $1 not found"
exit
else
echo "found"
fi
echo "Checking out $1 branch..."
if git show-ref --quiet "refs/heads/$1"; then
git checkout "$1"
else
git checkout --track "origin/$1"
fi
echo "Updating submodules..."
git submodule update --recursive
git fetch --recurse-submodules
echo "Deleting $1 branches from all subrepositories..."
for subdir in $(find . -maxdepth 10 -type d); do
if [ -e "$root_dir/$subdir/.git" ]; then
cd "$root_dir/$subdir"
branch_head_sha=$(git rev-parse --verify --quiet "origin/$1")
release_tag_sha=$(git rev-list --ignore-missing -n 1 "$2")
if [ "$branch_head_sha" == "" ]; then
echo "$subdir NOTE: Branch $1 not found. Skipping..."
continue
fi
if [ "$release_tag_sha" == "" ]; then
echo "$subdir NOTE: Release tag $2 not found. Skipping..."
continue
fi
if [ "$branch_head_sha" == "$release_tag_sha" ]; then
# delete branch from origin (Gerrit)
git push origin --delete "refs/heads/$1"
else
echo "$subdir NOTE: Branch head is not same as release tag. Skipping..."
fi
fi
done
cd $root_dir
echo "Deleting $1 branches done"
|