gitoria
All repositories: gitoria
2.5 KB
#!/bin/sh# The forced command of every key: `gitoria-shell <user id>`. What the client asked is in SSH_ORIGINAL_COMMAND and may only be# git-upload-pack (clone, fetch) or git-receive-pack (push) of ONE repository '<slug>.git'; the app decides who may push.user=$1cmd=${SSH_ORIGINAL_COMMAND:-}refuse() { echo "gitoria: $1" >&2; exit 1; }case "$cmd" in"git-upload-pack "*) service=git-upload-pack; write=0 ;;"git-receive-pack "*) service=git-receive-pack; write=1 ;;*) refuse "only git clone, fetch and push work over ssh (no shell)" ;;esacarg=${cmd#* }arg=${arg#\'}; arg=${arg%\'}; arg=${arg#/}slug=${arg%.git}[ "$arg" = "$slug.git" ] || refuse "no such repository"# <name> or <org>/<name> (an organization's repo, GO34): each part a-z 0-9 and hyphens, 2-40 characterscase "$slug" in*/*/*) refuse "no such repository" ;;esacfor part in $(echo "$slug" | tr '/' ' '); docase "$part" in""|*[!a-z0-9-]*|-*|*-) refuse "no such repository" ;;esac[ ${#part} -ge 2 ] && [ ${#part} -le 40 ] || refuse "no such repository"donestatus=$(curl -sS --max-time 10 -G -o /tmp/gitoria-access.$$ -w '%{http_code}' -H "X-Gitoria-Secret: $(cat /run/gitoria-secret)" \--data-urlencode "user=$user" --data-urlencode "slug=$slug" --data-urlencode "write=$write" "$(cat /run/gitoria-url)/__git/access") || status=000msg=$(cat /tmp/gitoria-access.$$ 2>/dev/null); rm -f /tmp/gitoria-access.$$[ "$status" = 200 ] || refuse "${msg:-the server did not answer}"# the app answers "ok <real name>": a moved repo is served from its new placereal=${msg#ok }; real=$(echo "$real" | tr -d '\n')case "$real" in""|*[!a-z0-9/-]*|*..*|/*|*/) real=$slug ;;esac# refs/pull/* is gitoria's (pull request heads): the push is refused for it, as over HTTPS (git >= 2.31 reads these variables).# core.hooksPath: the pre-receive that refuses a direct push to the main branch when the owner switched that on (gitoria#50)export GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=receive.hideRefs GIT_CONFIG_VALUE_0=refs/pull GIT_CONFIG_KEY_1=core.hooksPath GIT_CONFIG_VALUE_1=/usr/local/share/gitoria-hooks# a push: the app numbers the repo's pull requests before, and compares them with git after (notifyPush, syncPulls). A failure of that call never fails the push.pushed() { curl -sS --max-time 10 -G -o /dev/null -H "X-Gitoria-Secret: $(cat /run/gitoria-secret)" \--data-urlencode "user=$user" --data-urlencode "slug=$real" --data-urlencode "phase=$1" "$(cat /run/gitoria-url)/__git/pushed" >/dev/null 2>&1 || true; }[ "$write" = 1 ] && pushed before"$service" "/repos/$real.git"rc=$?[ "$write" = 1 ] && [ "$rc" = 0 ] && pushed afterexit $rc
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
- fe209ffeMerge branch 'w56-owner-members' into mainGitoria
- fa0754c8|||PR repository owner transfer and members API (#55)mre
- 8862e537Merge branch 'w55-rename-org' into mainGitoria
- 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
- 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
- 499f25f2Review fixes for the Settings organization move (#53)mre
- ed3b922b|||PR move a repository into an organization in Settings (#53)mre
- 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
- 9f7ce8d8Preserve rename compatibility and live page titlesmre
- c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
- ce08920dMerge branch 'w52c-header-phone' into mainGitoria
- 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
- e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
- c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
- 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
- 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
- 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
- 155861f6Merge branch 'w52-person-approval' into mainGitoria
- b5435de8|||PR person approvals: second Kunibert round (#52)mre
- 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre