-
Notifications
You must be signed in to change notification settings - Fork 12
/
kerndev-update
executable file
·77 lines (57 loc) · 1.41 KB
/
kerndev-update
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
#!/bin/bash
set -e; set -o pipefail; source kerndev-shared.sh
output_format="%-15s\t%s\n"
repos_path="$(script_dir)/.repos"
# Functions.
# Enter $1, stash if necessary, and store previous reference in $prevref.
function enterdir()
{
push $1
prevref=$(git rev-parse --abbrev-ref=strict HEAD)
# If this is 'HEAD', we can't find a matching branch so just use the
# commit hash instead.
[[ "$prevref" == "HEAD" ]] && prevref=$(git rev-parse HEAD)
changed=$(git status --porcelain)
if [[ -n "$changed" ]]; then
git stash -q --include-untracked
stashed=y
fi
}
# Resore $prevref, if stashed changes, pop them.
function exitdir()
{
git checkout -q $prevref
if [[ -n "$stashed" ]]; then
git stash pop -q >/dev/null
unset stashed
fi
pop
}
# Update kernel tree.
#
# $1: Directory of kernel tree.
# $2...: Branches to update.
function update()
{
dir=$1
shift
enterdir $dir
for branch in $@; do
printf $output_format $branch $PWD
git checkout --quiet $branch
git pull --quiet --rebase --strategy-option=theirs
done
exitdir
}
# The .repos file is of the following format:
# <path to kernel1> branch1 branch2 ... branchN
# <path to kernel2> branch1 branch2 ... branchN
# ...
# <path to kernelN> branch1 branch2 ... branchN
[[ -f "$repos_path" ]] || fatal 'Missing .repos'
echo Updating linux git trees...
printf $output_format "BRANCH" "DIR"
while read line; do
update $line
done < "$repos_path"
say_done