diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2025-07-16 19:45:24 -0400 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2025-07-16 19:45:24 -0400 |
| commit | 6d02c6da38bdad037b931289f4af3f31bbfb1272 (patch) | |
| tree | de852e6b2e08c093cc2c0874aa0f8edb0e4afc02 /executables/bin | |
| parent | Use C-; for tmux term (diff) | |
| download | dotfiles-6d02c6da38bdad037b931289f4af3f31bbfb1272.zip | |
Add migrate to sourcehut script
Diffstat (limited to 'executables/bin')
| -rwxr-xr-x | executables/bin/migrate-to-sourcehut | 76 |
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 "$@" |