[med-svn] [Git][med-team/community/helper-scripts][master] Add script replacing pkg-config2pkgconf in all local repositories, enable dry-run and force-push
Andreas Tille (@tille)
gitlab at salsa.debian.org
Tue Mar 10 08:53:14 GMT 2026
Andreas Tille pushed to branch master at Debian Med / community / helper-scripts
Commits:
22cc6022 by Andreas Tille at 2026-03-10T09:52:51+01:00
Add script replacing pkg-config2pkgconf in all local repositories, enable dry-run and force-push
- - - - -
1 changed file:
- + pkg-config2pkgconf
Changes:
=====================================
pkg-config2pkgconf
=====================================
@@ -0,0 +1,165 @@
+#!/bin/bash
+# Iterates over all git repositories below the current directory,
+# replaces pkg-config with pkgconf in debian/control Build-Depends,
+# adds a debian/changelog entry and commits the change.
+#
+# Options:
+# -f, --force Push changes after committing (with -o ci.skip)
+# -d, --dry Dry-run: only report what would be done, no changes
+
+set -euo pipefail
+
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+CYAN='\033[0;36m'
+BOLD='\033[1m'
+RESET='\033[0m'
+
+info() { echo -e "${CYAN}[INFO]${RESET} $*"; }
+ok() { echo -e "${GREEN}[OK]${RESET} $*"; }
+warn() { echo -e "${YELLOW}[WARN]${RESET} $*"; }
+changed() { echo -e "${BOLD}${GREEN}[CHANGED]${RESET} $*"; }
+dry() { echo -e "${YELLOW}[DRY]${RESET} $*"; }
+
+FORCE=false
+DRY=false
+
+usage() {
+ cat <<EOF
+Usage: $(basename "$0") [OPTIONS]
+
+Finds all git repositories below the current directory, replaces the
+Build-Depends entry 'pkg-config' with 'pkgconf' in debian/control,
+creates a changelog entry and commits the result.
+
+Options:
+ -f, --force Push commits to remote (with -o ci.skip)
+ -d, --dry Dry-run mode – report only, no modifications
+ -h, --help Show this help
+EOF
+}
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ -f|--force) FORCE=true ;;
+ -d|--dry) DRY=true ;;
+ -h|--help) usage; exit 0 ;;
+ *) echo "Unknown option: $1"; usage; exit 1 ;;
+ esac
+ shift
+done
+
+if $FORCE && $DRY; then
+ warn "--force and --dry are mutually exclusive; ignoring --force"
+ FORCE=false
+fi
+
+
+# Run a command, or only print it in dry-run mode.
+run() {
+ if $DRY; then
+ dry "Would run: $*"
+ else
+ "$@"
+ fi
+}
+
+# Add a debian/changelog entry using dch.
+# $1 = repository root $2 = package name
+add_changelog_entry() {
+ local repo_root="$1"
+ local pkg_name="$2"
+
+ if $DRY; then
+ dry "Would add debian/changelog entry in $pkg_name: Replace pkg-config with pkgconf in Build-Depends"
+ return
+ fi
+
+ (
+ cd "$repo_root"
+ dch --no-auto-nmu "Replace pkg-config with pkgconf in Build-Depends"
+ )
+}
+
+# Main loop
+START_DIR="$(pwd)"
+CHANGED_REPOS=()
+
+info "Searching for git repositories under: $START_DIR"
+$DRY && warn "DRY-RUN mode active – nothing will be modified"
+$FORCE && info "FORCE mode active – repositories will be pushed after commit"
+
+# find all .git directories (handles nested repos)
+while IFS= read -r git_dir; do
+ repo_root="$(dirname "$git_dir")"
+ control="$repo_root/debian/control"
+
+ if [[ ! -f "$control" ]]; then
+ continue
+ fi
+
+ # Match pkg-config as a standalone word (not pkgconf, not pkg-config-dev etc.)
+ if ! grep -qP '\bpkg-config\b' "$control"; then
+ continue
+ fi
+
+ pkg_name="$(grep -m1 '^Source:' "$control" | awk '{print $2}')"
+ [[ -z "$pkg_name" ]] && pkg_name="$(basename "$repo_root")"
+
+ info "Found match in package: ${BOLD}$pkg_name${RESET} ($repo_root)"
+
+ # Update repository
+ info " Pulling latest changes for $pkg_name"
+ # Argh, some branches might be no remote tracking ref set - make sure this is done before `gbp pull`
+ for branch in upstream pristine-tar; do
+ if git -C "$repo_root" show-ref --verify --quiet "refs/heads/$branch" && \
+ git -C "$repo_root" show-ref --verify --quiet "refs/remotes/origin/$branch"; then
+ tracking="$(git -C "$repo_root" for-each-ref --format='%(upstream)' "refs/heads/$branch")"
+ if [[ -z "$tracking" ]]; then
+ warn " Fixing missing tracking ref for '$branch' in $pkg_name"
+ run git -C "$repo_root" branch --set-upstream-to="origin/$branch" "$branch"
+ fi
+ fi
+ done
+ run sh -c "cd '$repo_root' && gbp pull"
+
+ # Replace exactly 'pkg-config' with 'pkgconf' in Build-Depends lines.
+ # Uses a word-boundary Perl regex to avoid partial matches.
+ if $DRY; then
+ dry "Would replace 'pkg-config' → 'pkgconf' in $control"
+ else
+ perl -i -pe 's/\bpkg-config\b/pkgconf/g' "$control"
+ ok " Replaced pkg-config → pkgconf in debian/control"
+ fi
+
+ add_changelog_entry "$repo_root" "$pkg_name"
+
+ if $DRY; then
+ dry "Would stage debian/control and debian/changelog and commit in $pkg_name"
+ else
+ git -C "$repo_root" add debian/control debian/changelog
+ git -C "$repo_root" commit \
+ -m "Replace pkg-config with pkgconf in Build-Depends"
+ ok " Committed in $pkg_name"
+ fi
+
+ if $FORCE; then
+ run git -C "$repo_root" push -o ci.skip
+ ok " Pushed $pkg_name (ci.skip)"
+ fi
+
+ CHANGED_REPOS+=("$pkg_name")
+ changed "$pkg_name"
+
+done < <(find "$START_DIR" -name ".git" -type d | sort)
+
+echo ""
+if [[ ${#CHANGED_REPOS[@]} -eq 0 ]]; then
+ info "No repositories required changes."
+else
+ echo -e "${BOLD}Summary – repositories updated (${#CHANGED_REPOS[@]}):${RESET}"
+ for r in "${CHANGED_REPOS[@]}"; do
+ echo -e " ${GREEN}✔${RESET} $r"
+ done
+fi
View it on GitLab: https://salsa.debian.org/med-team/community/helper-scripts/-/commit/22cc6022285d269802870c153535559c2a38a972
--
View it on GitLab: https://salsa.debian.org/med-team/community/helper-scripts/-/commit/22cc6022285d269802870c153535559c2a38a972
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20260310/fd156f50/attachment-0001.htm>
More information about the debian-med-commit
mailing list