Lightweight and easily self-hostable Git forge. git.poy.ooo
git-forge selfhosting homebrew
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950package ssh
import ( "errors" "farga/db/types" "fmt" "strings"
"golang.org/x/crypto/ssh")
func sendExitStatus(channel ssh.Channel, code int) { type exitStatusMsg struct{ Status uint32 } channel.SendRequest("exit-status", false, ssh.Marshal(&exitStatusMsg{Status: uint32(code)}))}
func closeChannel(channel ssh.Channel, req *ssh.Request, err string) { fmt.Fprintln(channel.Stderr(), err) req.Reply(false, nil) channel.CloseWrite() sendExitStatus(channel, 1)}
// parses the git command's raw arguments and returns the user, the repo's name, and an error if anything goes south.func UserAndRepo(store Store, raw string) (*types.User, string, error) { if strings.Contains(raw, "..") { return nil, "", fmt.Errorf("invalid repo name") }
clean := strings.TrimPrefix(raw, "/") clean = strings.TrimPrefix(clean, "~")
args := strings.Split(clean, "/")
if len(args) < 2 { return nil, "", errors.New("Invalid git argument.") }
userHandle := args[0] repoName, _ := strings.CutSuffix(args[1], ".git")
user, err := store.UserHandle(userHandle)
if err != nil { return nil, "", errors.New("No such user found") }
return user, repoName, nil}