gitoria
All repositories: gitoria
3.3 KB
// tools/move-repo.hl — MOVE (RENAME + TRANSFER) A REPO WITH ITS WHOLE HISTORY (ticket gitoria#34, GO34). The SAME bare repository is// moved (a rename of its folder, nothing is pushed again), the repo's row gets the new full name and visibility, its member list goes// with it, and the OLD name stays as a forward (lib/forwards.hl): the old address shows "moved to …", git over HTTP and SSH on the old path// is served from the new place.// GITORIA_STORAGE=<abs table dir> GITORIA_GIT=<abs git root> bin/hybriel tools/move-repo.hl <from> <to> <public|private>// from the repo's current full name, e.g. routger to the new one: `name` (stays top level) or `org/name`, e.g. einicher-ai/hyper-conductor// last the visibility AFTER the move (a parameter on purpose: nobody decides it here); an organization that does not exist yet is made with// this visibility and the repo's owner as its owner. Run it with the app STOPPED (it holds the tables), after a backup.// Prints what it did; non-zero exit on any refusal; nothing is changed before every check passed.import { args, run, env } from 'hl:proc'import { exists, mkDir } from 'hl:fs'import { gitRoot, repoDir } from '../lib/git.hl'import { reposTable, repoBySlug, nameTaken } from '../lib/repos.hl'import { withChange, fullNameError } from '../lib/repos-helpers.hl'import { orgBySlug, putOrg } from '../lib/orgs.hl'import { moveMembers, refOfRepo } from '../lib/members.hl'import { putForward, forwardOf } from '../lib/forwards.hl'a = args()if (a.length != 3) { hlError('usage: move-repo.hl <from> <to> <public|private>') }oldN = a[0]to = a[1]vis = a[2]if (env('GITORIA_STORAGE') == null || !env('GITORIA_STORAGE').startsWith('/')) { hlError('set GITORIA_STORAGE to the ABSOLUTE table directory') }if (vis != 'public' && vis != 'private') { hlError("the visibility must be 'public' or 'private'") }r = repoBySlug(oldN)if (r == null) { hlError("no repository '" + oldN + "'") }bad = fullNameError(to)if (bad != null) { hlError(bad) }if (to == oldN) { hlError('the new name is the old name') }if (repoBySlug(to) != null || forwardOf(to) != null) { hlError("'" + to + "' is taken") }if (!to.includes('/') && nameTaken(to)) { hlError("'" + to + "' is an organization's name") }if (!exists(repoDir(oldN))) { hlError('the bare repository ' + repoDir(oldN) + ' does not exist') }if (exists(repoDir(to))) { hlError(repoDir(to) + ' exists already') }i = to.indexOf('/')org = i < 0 ? '' : to.slice(0, i)priv = vis == 'private'if (org != '' && orgBySlug(org) == null) {if (putOrg(org, r.owner, priv) == null) { hlError('could not create the organization ' + org) }console.log('organization ' + org + ' created (' + vis + ')')}if (org != '' && !exists(gitRoot + '/' + org)) { mkDir(gitRoot + '/' + org, 493) }m = run(['mv', repoDir(oldN), repoDir(to)], { timeout = 60 })if (m == null || m.exit != 0) { hlError('could not move the folder') }reposTable.update(r.id, withChange(r, { slug = to org = org priv = priv }))after = reposTable.fetch(r.id)if (after == null || after.slug != to) {run(['mv', repoDir(to), repoDir(oldN)], { timeout = 60 })hlError('could not store the new name: ' + reposTable.lastError() + ' (the folder is back)')}moveMembers(refOfRepo(oldN), refOfRepo(to))putForward(oldN, to)console.log('moved ' + oldN + ' -> ' + to + ' (' + vis + '), history kept: ' + repoDir(to))
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 7e8aabeareport: W51b pull source verificationmre
- 6c18de76fix: preserve pull sources across containing branchesmre
- fc36fa2elog: W51b pull source bugmre
- 56bc1220log: v1.5.1 livemre
- 845fc0aareport: W51mre
- 83127391fix: return v1.5.1 app and merge error detailsmre
- b07d0e97log: W51 v1.5.1 startedmre
- 0b417d06docs: apps-api v1.5 user tokens (#48, W49)mre
- d046940alog: vinzenz contract note sentmre
- db443456log: vinzenz note retry 2mre
- 802f229alog: kunibert repo ping provenmre
- 2d2eaa92log: Kunibert connected to kunibert repomre
- 65d5f80alogmre
- dab74b0dW49 report, logmre
- fd4fc028Exercise member status reads with a populated check statemre
- 536ca6f9Allow repository members to read pull workflow APIs with user tokensmre
- 705dd834W49 missionmre
- b554cd5flogmre
- f4c9440ddeploy.sh: tar --hard-dereference for the live data backupmre
- 1a687b15Merge branch 'w48-member-merge'mre