mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-22 20:42:40 +00:00
Add config for default branch name (#171)
Co-authored-by: Thomas Miceli <27960254+thomiceli@users.noreply.github.com>
This commit is contained in:
parent
4bba26daf6
commit
2f8435892e
9 changed files with 73 additions and 42 deletions
|
@ -89,7 +89,7 @@ Opengist is now running on port 6157, you can browse http://localhost:6157
|
|||
|
||||
### From source
|
||||
|
||||
Requirements : [Git](https://git-scm.com/downloads) (2.20+), [Go](https://go.dev/doc/install) (1.20+), [Node.js](https://nodejs.org/en/download/) (16+)
|
||||
Requirements : [Git](https://git-scm.com/downloads) (2.28+), [Go](https://go.dev/doc/install) (1.20+), [Node.js](https://nodejs.org/en/download/) (16+)
|
||||
|
||||
```shell
|
||||
git clone https://github.com/thomiceli/opengist
|
||||
|
|
|
@ -18,6 +18,10 @@ opengist-home:
|
|||
# Name of the SQLite database file. Default: opengist.db
|
||||
db-filename: opengist.db
|
||||
|
||||
# Default branch name used by Opengist when initializing Git repositories.
|
||||
# If not set, uses the Git default branch name. See https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup#_new_default_branch
|
||||
git.default-branch:
|
||||
|
||||
# Set the journal mode for SQLite. Default: WAL
|
||||
# See https://www.sqlite.org/pragma.html#pragma_journal_mode
|
||||
sqlite.journal-mode: WAL
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
# Configuration Cheat Sheet
|
||||
|
||||
| YAML Config Key | Environment Variable | Default value | Description |
|
||||
|-----------------------|--------------------------|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------|
|
||||
|-----------------------|--------------------------|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| log-level | OG_LOG_LEVEL | `warn` | Set the log level to one of the following: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `panic`. |
|
||||
| log-output | OG_LOG_OUTPUT | `stdout,file` | Set the log output to one or more of the following: `stdout`, `file`. |
|
||||
| external-url | OG_EXTERNAL_URL | none | Public URL for the Git HTTP/SSH connection. If not set, uses the URL from the request. |
|
||||
| opengist-home | OG_OPENGIST_HOME | home directory | Path to the directory where Opengist stores its data. |
|
||||
| db-filename | OG_DB_FILENAME | `opengist.db` | Name of the SQLite database file. |
|
||||
| git.default-branch | OG_GIT_DEFAULT_BRANCH | none | Default branch name used by Opengist when initializing Git repositories. If not set, uses the Git default branch name. More info [here](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup#_new_default_branch) |
|
||||
| sqlite.journal-mode | OG_SQLITE_JOURNAL_MODE | `WAL` | Set the journal mode for SQLite. More info [here](https://www.sqlite.org/pragma.html#pragma_journal_mode) |
|
||||
| http.host | OG_HTTP_HOST | `0.0.0.0` | The host on which the HTTP server should bind. |
|
||||
| http.port | OG_HTTP_PORT | `6157` | The port on which the HTTP server should listen. |
|
||||
|
|
|
@ -35,7 +35,7 @@ Written in [Go](https://go.dev), Opengist aims to be fast and easy to deploy.
|
|||
## System requirements
|
||||
|
||||
[Git](https://git-scm.com/download) is obviously required to run Opengist, as it's the main feature of the app.
|
||||
Version **2.20** or later is recommended as the app has not been tested with older Git versions.
|
||||
Version **2.28** or later is recommended as the app has not been tested with older Git versions and some features would not work.
|
||||
|
||||
[OpenSSH](https://www.openssh.com/) suite if you wish to use Git over SSH.
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ chmod +x opengist
|
|||
## From source
|
||||
|
||||
Requirements :
|
||||
* [Git](https://git-scm.com/downloads) (2.20+)
|
||||
* [Git](https://git-scm.com/downloads) (2.28+)
|
||||
* [Go](https://go.dev/doc/install) (1.20+)
|
||||
* [Node.js](https://nodejs.org/en/download/) (16+)
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -37,7 +37,7 @@ func initialize() {
|
|||
if ok, err := config.CheckGitVersion(gitVersion); err != nil {
|
||||
log.Fatal().Err(err).Send()
|
||||
} else if !ok {
|
||||
log.Warn().Msg("Git version may be too old, as Opengist has not been tested prior git version 2.20. " +
|
||||
log.Warn().Msg("Git version may be too old, as Opengist has not been tested prior git version 2.28 and some features would not work. " +
|
||||
"Current git version: " + gitVersion)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue