From 6d02c6da38bdad037b931289f4af3f31bbfb1272 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Wed, 16 Jul 2025 19:45:24 -0400 Subject: Add migrate to sourcehut script --- executables/bin/migrate-to-sourcehut | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 executables/bin/migrate-to-sourcehut (limited to 'executables') diff --git a/executables/bin/migrate-to-sourcehut b/executables/bin/migrate-to-sourcehut new file mode 100755 index 0000000..d7e471a --- /dev/null +++ b/executables/bin/migrate-to-sourcehut @@ -0,0 +1,76 @@ +#!/bin/bash +set -euo pipefail +set -x + +REPOS_DIR="$HOME/src/" +SOURCEHUT_USER="eugenetriguba" + +main() { + parse_args "$@" + + cd "$REPOS_DIR" + for repo in */; do + if [ -d "$repo/.git" ]; then + echo "Processing $repo..." + cd "$repo" + + if ! git remote | grep -q "^origin$"; then + echo "No origin remote found for $repo, skipping..." + cd .. + continue + fi + + if ! git remote get-url origin | grep -q "git.sr.ht"; then + echo "Migrating $repo to SourceHut..." + + local repo_name + repo_name=$(git remote get-url origin | cut -d '/' -f 2 | cut -d '.' -f 1) + git remote remove origin + git remote add origin "git@git.sr.ht:~${SOURCEHUT_USER}/${repo_name}" + + local current_branch + current_branch=$(git branch --show-current) + if [ "$current_branch" = "master" ]; then + echo "Renaming master branch to main..." + git branch -m master main + fi + + git push --push-option visiblity="private" -u origin main + git push origin main --tags + fi + + cd .. + fi + done +} + +parse_args() { + while [[ $# -gt 0 ]]; do + case "$1" in + --repos-dir) + REPOS_DIR="$2" + shift 2 + ;; + --sourcehut-user) + SOURCEHUT_USER="$2" + shift 2 + ;; + *) + echo "Usage: $0 [--repos-dir ] [--sourcehut-user ]" + exit 1 + ;; + esac + + if [[ -z "$REPOS_DIR" || ! -d "$REPOS_DIR" ]]; then + echo "Invalid or empty REPOS_DIR: $REPOS_DIR" + exit 1 + fi + + if [[ -z "$SOURCEHUT_USER" ]]; then + echo "SOURCEHUT_USER must be specified." + exit 1 + fi + done +} + +main "$@" -- cgit v1.2.3