aboutsummaryrefslogtreecommitdiff
path: root/git_misc.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-12 19:16:41 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-12 19:16:41 +0800
commitf828acac387aacadd2884837402b0e32b2368470 (patch)
tree475c374f5e9b1205136cf03171867ead7fad4291 /git_misc.go
parenthttp_router.go: Move from router.go and fix conditional placement bug (diff)
downloadforge-f828acac387aacadd2884837402b0e32b2368470.tar.gz
forge-f828acac387aacadd2884837402b0e32b2368470.tar.zst
forge-f828acac387aacadd2884837402b0e32b2368470.zip
*.go: Use the database for repo info, and fix ssh cloning repo
Diffstat (limited to 'git_misc.go')
-rw-r--r--git_misc.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/git_misc.go b/git_misc.go
index 882c631..2d4c4d3 100644
--- a/git_misc.go
+++ b/git_misc.go
@@ -1,9 +1,9 @@
package main
import (
+ "context"
"errors"
"io"
- "path/filepath"
"strings"
"github.com/go-git/go-git/v5"
@@ -19,16 +19,13 @@ var (
err_getting_parent_commit_object = errors.New("Error getting parent commit object")
)
-func open_git_repo(group_name, repo_name string) (*git.Repository, error) {
- group_name, group_name_ok := misc.Sanitize_path(group_name)
- if !group_name_ok {
- return nil, err_unsafe_path
- }
- repo_name, repo_name_ok := misc.Sanitize_path(repo_name)
- if !repo_name_ok {
- return nil, err_unsafe_path
+func open_git_repo(ctx context.Context, group_name, repo_name string) (*git.Repository, error) {
+ var fs_path string
+ err := database.QueryRow(ctx, "SELECT r.filesystem_path FROM repos r JOIN groups g ON r.group_id = g.id WHERE g.name = $1 AND r.name = $2;", group_name, repo_name).Scan(&fs_path)
+ if err != nil {
+ return nil, err
}
- return git.PlainOpen(filepath.Join(config.Git.Root, group_name, repo_name+".git"))
+ return git.PlainOpen(fs_path)
}
type display_git_tree_entry_t struct {