srm

command module
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 20 Imported by: 0

README

Overview

srm is a work-in-progress command-line tool to migrate repositories from other git forges to sr.ht.

While srm is still a work-in-progress, it is designed to eagerly fail loudly if anything looks awry. It also takes a backup of the repository before applying any changes.

This repository, for example, was migrated with srm.

Quickstart

# Install srm
$ go install git.sr.ht/~illbjorn/srm@latest
# Migrate
$ srm -r '[git repo path]' -rr '${git_remote:-origin}' -ro '[~sr.ht username]' -rn '[sr.ht repo name]'

NOTE: Make sure you have ssh or https authentication for sr.ht configured (srm will use ssh by default)!

How it Works

Inputs

Input Flag Description Required?
Repository Root --repo-root, -r The path to the root of the repository to be migrated Yes
Repository Owner --repo-owner, -ro The sr.ht repository owner/username (INCLUDING THE ~) Yes
Repository Name --repo-name, -rn The sr.ht repository name to create Yes
Remote Name --repo-remote, -rr The git remote to repoint to the new sr.ht repository URL Yes
Use HTTPS --https By default the updated git remote will assume ssh. No
Input Translation Example

Consider an srm call like:

$ srm -r . -rr 'origin' -ro '~illbjorn' -rn 'srm-demo'

This will translate to:

  • A git repository in the current working directory (.) will have remote origin's URL updated to git@git.sr.ht:~illbjorn/srm-demo.

Workflow

  1. Parse and validate all required inputs are present.
  2. Run a series of pre-flight checks, including: a. Confirm the git status is clean. If not, the run will fail and a list of untracked or modified files will be presented. b. Confirm the command-line-provided git remote name actually exists.
  3. Enumerate the --repo-root directory, inventorying all nested files.
  4. Backup the repository. Since we're going to commit potentially a lot of changes and update the remote, a backup feels prudent. a. The repository's files will be archived to /tmp/srm-*******/backup.tar.gz.
  5. We evaluate all files under the repo root for language-specific transforms, and: a. In the case of Go: i. Recursively, from the provided root directory, look for go.mod files. ii. When a go.mod file is found:
    1. we parse the module name from it and evaluate it for the presence of any known git forges (currently just GH).
    2. If we find a known git forge prefix, we replace it in both the go.mod file and in any *.go files in the go.mod's own directory or any descendant directories thereunder (is that a word?).
  6. The git remote specified is updated to reflect the new sr.ht URL.
  7. All file changes are committed and pushed to the new sr.ht repository.

TODOs and Sharp Edges

  • Need to implement cleanup of the backup archive when the migration is successful (will leave in flag to preserve this archive in all cases).
  • Need to implement automatic restore of the backup archive to the repository directory in failure scenarios (currently you've got to grab and untar this archive manually if you encounter issues).
  • Evaluate additional languages for possible transform value.
  • To get something working in a shorter time, all git operations are performed by just calling a git binary on PATH. In the longer-term I would like to phase these out with proper git protocol (SSH and HTTPS) implementations.
  • TODO: Write up the rest of the TODOs.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL