mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-17 23:57:12 +02:00
Add config for default branch name (#171)
Co-authored-by: Thomas Miceli <27960254+thomiceli@users.noreply.github.com>
This commit is contained in:

committed by
Thomas Miceli

parent
4bba26daf6
commit
2f8435892e
@ -29,6 +29,8 @@ type config struct {
|
||||
OpengistHome string `yaml:"opengist-home" env:"OG_OPENGIST_HOME"`
|
||||
DBFilename string `yaml:"db-filename" env:"OG_DB_FILENAME"`
|
||||
|
||||
GitDefaultBranch string `yaml:"git.default-branch" env:"OG_GIT_DEFAULT_BRANCH"`
|
||||
|
||||
SqliteJournalMode string `yaml:"sqlite.journal-mode" env:"OG_SQLITE_JOURNAL_MODE"`
|
||||
|
||||
HttpHost string `yaml:"http.host" env:"OG_HTTP_HOST"`
|
||||
@ -176,8 +178,8 @@ func CheckGitVersion(version string) (bool, error) {
|
||||
return false, fmt.Errorf("invalid minor version number")
|
||||
}
|
||||
|
||||
// Check if version is prior to 2.20
|
||||
if major < 2 || (major == 2 && minor < 20) {
|
||||
// Check if version is prior to 2.28
|
||||
if major < 2 || (major == 2 && minor < 28) {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
|
@ -4,9 +4,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@ -14,6 +11,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -61,12 +62,14 @@ func TmpRepositoriesPath() string {
|
||||
func InitRepository(user string, gist string) error {
|
||||
repositoryPath := RepositoryPath(user, gist)
|
||||
|
||||
cmd := exec.Command(
|
||||
"git",
|
||||
"init",
|
||||
"--bare",
|
||||
repositoryPath,
|
||||
)
|
||||
var args []string
|
||||
args = append(args, "init")
|
||||
if config.C.GitDefaultBranch != "" {
|
||||
args = append(args, "--initial-branch", config.C.GitDefaultBranch)
|
||||
}
|
||||
args = append(args, "--bare", repositoryPath)
|
||||
|
||||
cmd := exec.Command("git", args...)
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
|
@ -271,6 +271,27 @@ func TestInitViaGitInit(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGitInitBranchNames(t *testing.T) {
|
||||
setup(t)
|
||||
defer teardown(t)
|
||||
|
||||
cmd := exec.Command("git", "symbolic-ref", "HEAD")
|
||||
cmd.Dir = RepositoryPath("thomas", "gist1")
|
||||
out, err := cmd.Output()
|
||||
require.NoError(t, err, "Could not run git command")
|
||||
require.Equal(t, "refs/heads/master", strings.TrimSpace(string(out)), "Repository should have master branch as default")
|
||||
|
||||
config.C.GitDefaultBranch = "main"
|
||||
|
||||
err = InitRepository("thomas", "gist2")
|
||||
require.NoError(t, err)
|
||||
cmd = exec.Command("git", "symbolic-ref", "HEAD")
|
||||
cmd.Dir = RepositoryPath("thomas", "gist2")
|
||||
out, err = cmd.Output()
|
||||
require.NoError(t, err, "Could not run git command")
|
||||
require.Equal(t, "refs/heads/main", strings.TrimSpace(string(out)), "Repository should have main branch as default")
|
||||
}
|
||||
|
||||
func commitToBare(t *testing.T, user string, gist string, files map[string]string) {
|
||||
err := CloneTmp(user, gist, gist, "thomas@mail.com", true)
|
||||
require.NoError(t, err, "Could not commit to repository")
|
||||
|
Reference in New Issue
Block a user