Skip to content

Commit

Permalink
fix(git): allow user repos
Browse files Browse the repository at this point in the history
Allow using nested repos similar to GitHub/Gitlab and the likes.
<user>/<repo>.git but also allow repos living in the root path.

Fixes: charmbracelet/soft-serve#120
  • Loading branch information
aymanbagabas committed Nov 9, 2022
1 parent 7e511f1 commit 8808de5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ func Middleware(repoDir string, gh Hooks) wish.Middleware {
cmd := s.Command()
if len(cmd) == 2 {
gc := cmd[0]
repo := cmd[1] // cmd[1] should be `/REPO`
// repo should be in the form of "repo.git" or "user/repo.git"
repo := strings.TrimSuffix(strings.TrimPrefix(cmd[1], "/"), "/")
repo = filepath.Clean(repo)
repo = filepath.Base(repo)
if n := strings.Count(repo, "/"); n > 1 {
Fatal(s, ErrInvalidRepo)
return
}
pk := s.PublicKey()
access := gh.AuthRepo(repo, pk)
switch gc {
Expand Down Expand Up @@ -139,6 +143,7 @@ func gitPack(s ssh.Session, gitCmd string, repoDir string, repo string) error {
if err != nil {
return err
}
// Needed for git dumb http server
return runGit(s, rp, "update-server-info")
default:
return fmt.Errorf("unknown git command: %s", gitCmd)
Expand Down

0 comments on commit 8808de5

Please sign in to comment.