-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeb-pkg-update
More file actions
executable file
·161 lines (150 loc) · 6.32 KB
/
Copy pathdeb-pkg-update
File metadata and controls
executable file
·161 lines (150 loc) · 6.32 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env bash
#
# deb-pkg-update — propagate a debian/ packaging change (already committed on
# debian/sid) to all active distro branches, with a debian-revision (-N) bump.
#
# Usage: ./deb-pkg-update <repo> [<commit>...] -m "<message>"
# ./deb-pkg-update <repo> <commit> [<commit>...] --no-bump
#
# <repo> managed checkout directory (e.g. oxen-mq)
# <commit> packaging commit(s) to propagate. In the default (bumping) mode
# they must live on debian/sid; if omitted they are auto-detected
# (sid commits since the last changelog entry that touch something
# other than debian/changelog|control), and you confirm if >1.
# -m MSG changelog/commit message (required unless --no-bump)
# --no-bump cherry-pick the given commit(s) onto every active branch that
# lacks them, with NO version bump and NO changelog entry (use when
# a version bump is coming separately). Explicit commit ref(s) are
# required; they may live on any branch (e.g. a fix committed on one
# distro). Branches that already have the commit — or don't exist yet
# — are skipped. -m is not accepted.
#
# Default workflow: first make + commit your packaging change on debian/sid
# yourself, then run this. It bumps sid's changelog, then for every other branch
# it cherry-picks the packaging commit(s) and bumps that branch's changelog. It
# does NOT push (use deb-push). Cherry-pick conflicts stop with resume instructions.
set -euo pipefail
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.bash"
INVOCATION="$0 $*"
# Auto-detect packaging commits on the (checked-out) debian/sid branch: commits
# since the last changelog entry that change more than just changelog/control.
detect_pkg_commits() {
local last c files
last="$(git log -1 --format=%H -- debian/changelog)"
[ -n "$last" ] || last="$(git rev-list --max-parents=0 HEAD | tail -1)"
while read -r c; do
[ -n "$c" ] || continue
files="$(git show --name-only --format='' "$c" | sed '/^$/d')"
if printf '%s\n' "$files" | grep -qvE '^debian/(changelog|control)$'; then
printf '%s\n' "$c"
fi
done < <(git rev-list --reverse "$last..HEAD")
}
[ $# -ge 1 ] || usage
case "$1" in -h|--help) usage 0 ;; esac
repo="$1"; shift
resolve_repo "$repo"
begin_or_resume pkg-update
if [ "$RESUMING" = 0 ]; then
COMMIT_MSG=""
NOBUMP=0
commit_args=()
while [ $# -gt 0 ]; do
case "$1" in
-m) shift; [ $# -gt 0 ] || die "-m requires a message"; COMMIT_MSG="$1" ;;
-m*) COMMIT_MSG="${1#-m}" ;;
--no-bump) NOBUMP=1 ;;
-h|--help) usage 0 ;;
-*) die "unknown option: $1" ;;
*) commit_args+=("$1") ;;
esac
shift
done
require_clean_tree
msg "Fetching origin..."
git fetch -q origin
if [ "$NOBUMP" = 1 ]; then
[ -z "$COMMIT_MSG" ] || die "--no-bump writes no changelog entry, so it doesn't take -m"
[ "${#commit_args[@]}" -gt 0 ] || die "--no-bump needs explicit commit ref(s) to cherry-pick"
COMMITS=()
for c in "${commit_args[@]}"; do
h="$(git rev-parse --verify -q "$c^{commit}")" || die "unknown commit: $c"
COMMITS+=("$h")
done
# Operate on the active branches that exist; skip ones not yet created
# (e.g. a distro that deb-version-bump will add later).
order=()
for b in "${distros[@]}"; do
if branch_exists "$b"; then order+=("$b")
else msg "[$(cpkg "$b")] not present — $C_DIM skipping$C_RESET"; fi
done
[ "${#order[@]}" -gt 0 ] || die "no active branches exist to cherry-pick onto"
TARGET="${order[*]}"
msg "Cherry-picking (no bump) onto: ${order[*]}"
else
[ -n "$COMMIT_MSG" ] || die "a changelog message (-m) is required"
require_branches
checkout_uptodate debian/sid
COMMITS=()
if [ "${#commit_args[@]}" -gt 0 ]; then
for c in "${commit_args[@]}"; do
h="$(git rev-parse --verify -q "$c^{commit}")" || die "unknown commit: $c"
COMMITS+=("$h")
done
else
mapfile -t COMMITS < <(detect_pkg_commits)
[ "${#COMMITS[@]}" -ge 1 ] || die \
"no packaging commits found on debian/sid since the last changelog entry.
Commit your debian/ change on debian/sid first, or pass explicit commit refs."
if [ "${#COMMITS[@]}" -gt 1 ]; then
msg "Auto-detected ${#COMMITS[@]} commits to propagate:"
for c in "${COMMITS[@]}"; do msg " $(git log -1 --oneline "$c")"; done
confirm "Propagate these ${#COMMITS[@]} commits?" ||
die "aborted; re-run passing the exact commit ref(s) you want."
fi
fi
cur="$(changelog_version debian/sid)"
VERSION_BASE="$(bump_revision "$cur")"
msg "Revision bump: $cur -> $VERSION_BASE"
fi
save_state "" ""
fi
proc_pkgupdate() {
local b="$1"
# --no-bump: just cherry-pick the commit(s) this branch lacks; no changelog.
if [ "${NOBUMP:-0}" = 1 ]; then
if [ -z "$RESUME_PHASE" ]; then
checkout_uptodate "$b"
local pick=() c
for c in "${COMMITS[@]}"; do
git merge-base --is-ancestor "$c" HEAD 2>/dev/null || pick+=("$c")
done
if [ "${#pick[@]}" -eq 0 ]; then
msg " already present — $C_DIM skipping$C_RESET"
return
fi
save_state "$b" cherry-pick
git cherry-pick "${pick[@]}" ||
conflict_halt "$b" cherry-pick "cherry-picking the packaging change onto $b"
else
ensure_resolved "$b" "$RESUME_PHASE"
fi
return
fi
if [ "$b" = debian/sid ]; then
checkout_uptodate debian/sid # packaging commit(s) already present here
finalize_branch "$b"
return
fi
if [ -z "$RESUME_PHASE" ]; then
checkout_uptodate "$b"
save_state "$b" cherry-pick
git cherry-pick "${COMMITS[@]}" ||
conflict_halt "$b" cherry-pick "cherry-picking the packaging change onto $b"
else
ensure_resolved "$b" "$RESUME_PHASE"
fi
finalize_branch "$b"
}
run_multibranch proc_pkgupdate
push_hint