aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xexecutables/bin/migrate-to-sourcehut76
1 files changed, 76 insertions, 0 deletions
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 <path>] [--sourcehut-user <username>]"
+ 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 "$@"