gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit34143d2c34143d2cgitoria#46: closing brace of appComments lost in the mergemre34143d2c/tools/move-repo.hl

3.3 KB

  1. // tools/move-repo.hl — MOVE (RENAME + TRANSFER) A REPO WITH ITS WHOLE HISTORY (ticket gitoria#34, GO34). The SAME bare repository is
  2. // 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
  3. // 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
  4. // is served from the new place.
  5. // GITORIA_STORAGE=<abs table dir> GITORIA_GIT=<abs git root> bin/hybriel tools/move-repo.hl <from> <to> <public|private>
  6. // 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
  7. // last the visibility AFTER the move (a parameter on purpose: nobody decides it here); an organization that does not exist yet is made with
  8. // this visibility and the repo's owner as its owner. Run it with the app STOPPED (it holds the tables), after a backup.
  9. // Prints what it did; non-zero exit on any refusal; nothing is changed before every check passed.
  10. import { args, run, env } from 'hl:proc'
  11. import { exists, mkDir } from 'hl:fs'
  12. import { gitRoot, repoDir } from '../lib/git.hl'
  13. import { reposTable, repoBySlug, nameTaken } from '../lib/repos.hl'
  14. import { withChange, fullNameError } from '../lib/repos-helpers.hl'
  15. import { orgBySlug, putOrg } from '../lib/orgs.hl'
  16. import { moveMembers, refOfRepo } from '../lib/members.hl'
  17. import { putForward, forwardOf } from '../lib/forwards.hl'
  18. a = args()
  19. if (a.length != 3) { hlError('usage: move-repo.hl <from> <to> <public|private>') }
  20. oldN = a[0]
  21. to = a[1]
  22. vis = a[2]
  23. if (env('GITORIA_STORAGE') == null || !env('GITORIA_STORAGE').startsWith('/')) { hlError('set GITORIA_STORAGE to the ABSOLUTE table directory') }
  24. if (vis != 'public' && vis != 'private') { hlError("the visibility must be 'public' or 'private'") }
  25. r = repoBySlug(oldN)
  26. if (r == null) { hlError("no repository '" + oldN + "'") }
  27. bad = fullNameError(to)
  28. if (bad != null) { hlError(bad) }
  29. if (to == oldN) { hlError('the new name is the old name') }
  30. if (repoBySlug(to) != null || forwardOf(to) != null) { hlError("'" + to + "' is taken") }
  31. if (!to.includes('/') && nameTaken(to)) { hlError("'" + to + "' is an organization's name") }
  32. if (!exists(repoDir(oldN))) { hlError('the bare repository ' + repoDir(oldN) + ' does not exist') }
  33. if (exists(repoDir(to))) { hlError(repoDir(to) + ' exists already') }
  34. i = to.indexOf('/')
  35. org = i < 0 ? '' : to.slice(0, i)
  36. priv = vis == 'private'
  37. if (org != '' && orgBySlug(org) == null) {
  38. if (putOrg(org, r.owner, priv) == null) { hlError('could not create the organization ' + org) }
  39. console.log('organization ' + org + ' created (' + vis + ')')
  40. }
  41. if (org != '' && !exists(gitRoot + '/' + org)) { mkDir(gitRoot + '/' + org, 493) }
  42. m = run(['mv', repoDir(oldN), repoDir(to)], { timeout = 60 })
  43. if (m == null || m.exit != 0) { hlError('could not move the folder') }
  44. reposTable.update(r.id, withChange(r, { slug = to org = org priv = priv }))
  45. after = reposTable.fetch(r.id)
  46. if (after == null || after.slug != to) {
  47. run(['mv', repoDir(to), repoDir(oldN)], { timeout = 60 })
  48. hlError('could not store the new name: ' + reposTable.lastError() + ' (the folder is back)')
  49. }
  50. moveMembers(refOfRepo(oldN), refOfRepo(to))
  51. putForward(oldN, to)
  52. console.log('moved ' + oldN + ' -> ' + to + ' (' + vis + '), history kept: ' + repoDir(to))

Branches

Latest commits

  • 34143d2cgitoria#46: closing brace of appComments lost in the mergemre
  • 54927c9cgitoria#46: PR statuses and required checks before merge (merge w46-status)mre
  • 187e1871gitoria#46: badges without decorative bordersmre
  • 6b022798gitoria#46: tests/status.mjs in GATESmre
  • c6162f00gitoria#46: status badges on /pulls, Required before merge in Settingsmre
  • e5a0b64egitoria#46: PUT statuses/<sha>, required contexts block the merge on the servermre
  • 26a140e3gitoria#44: reviews, inline threads, replies, conversation for apps (merge w44-reviews)mre
  • 888dbf87gitoria#44: unknown API paths answer the contract's JSON 404 and sit above the page routesmre
  • ea587d90gitoria#44: reviews with inline threads, replies, resolve and the PR conversation for apps (lib/reviews.hl, tests/reviews.mjs)mre
  • 49533a50gitoria#43: signed events to connected apps (merge w43-events)mre
  • 1a1e87d5gitoria#43: the sender never writes the apps row; Settings shows the newest deliverymre
  • cd442066gitoria#43: app-auth unit test reads the apps table from its new filemre
  • 5dccbe38gitoria#43: in-flight rows are left alone by the other process; gate in deploy.sh; READMEmre
  • 8c8805f3merge main (gitoria#42), delivery log and redelivery routes, sweep fixmre
  • 5a996ea8gitoria#42: short-lived app tokens, read-only git fetch with them (merge w42-app-token)mre
  • afdb0cbfgitoria#43: rename the moved helper (name clash in the browser build)mre
  • 15e01e94gitoria#43: tests/events.mjs and its probemre
  • 77829b73gitoria#43: signed events to connected apps (deliveries table, sender timer, pull_request events, ping)mre
  • b5d696fegitoria#42: app tokens (gat_, one hour), appOfRequest, app token as the git read passwordmre
  • 1997e77dgitoria#40: stable PR numbers, refs/pull/N/head, ssh pushes reach the app (merge w40-pr-number)mre