mirror of https://git.jolheiser.com/ugit.git
Compare commits
3 Commits
5809db19f5
...
20a8451427
Author | SHA1 | Date |
---|---|---|
|
20a8451427 | |
|
d4b287ed08 | |
|
a9208d2fe2 |
|
@ -11,6 +11,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
"github.com/go-chi/httplog/v2"
|
"github.com/go-chi/httplog/v2"
|
||||||
|
@ -111,7 +112,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
signal.Notify(ch, os.Kill, os.Interrupt)
|
signal.Notify(ch, syscall.SIGTERM, os.Interrupt)
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -5,6 +5,7 @@ go 1.23.1
|
||||||
toolchain go1.23.3
|
toolchain go1.23.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/alecthomas/assert/v2 v2.11.0
|
||||||
github.com/alecthomas/chroma/v2 v2.15.0
|
github.com/alecthomas/chroma/v2 v2.15.0
|
||||||
github.com/charmbracelet/ssh v0.0.0-20241211182756-4fe22b0f1b7c
|
github.com/charmbracelet/ssh v0.0.0-20241211182756-4fe22b0f1b7c
|
||||||
github.com/charmbracelet/wish v1.4.4
|
github.com/charmbracelet/wish v1.4.4
|
||||||
|
@ -25,6 +26,7 @@ require (
|
||||||
dario.cat/mergo v1.0.1 // indirect
|
dario.cat/mergo v1.0.1 // indirect
|
||||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||||
github.com/ProtonMail/go-crypto v1.1.4 // indirect
|
github.com/ProtonMail/go-crypto v1.1.4 // indirect
|
||||||
|
github.com/alecthomas/repr v0.4.0 // indirect
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/bubbletea v1.2.4 // indirect
|
github.com/charmbracelet/bubbletea v1.2.4 // indirect
|
||||||
|
@ -46,6 +48,7 @@ require (
|
||||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||||
|
github.com/hexops/gotextdiff v1.0.3 // indirect
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
sha256-+pv4dv79+/WUMiPmlK9eebS3NR6aT8q/Cw+MZ5BWoxg=
|
sha256-L87PnM43gHrDcsRr3wnkB4e1Th2S0LsSwkXuebAFH44=
|
|
@ -0,0 +1,45 @@
|
||||||
|
package git_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alecthomas/assert/v2"
|
||||||
|
"go.jolheiser.com/ugit/internal/git"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEnsureRepo(t *testing.T) {
|
||||||
|
tmp := t.TempDir()
|
||||||
|
|
||||||
|
ok, err := git.PathExists(filepath.Join(tmp, "test"))
|
||||||
|
assert.False(t, ok, "repo should not exist yet")
|
||||||
|
assert.NoError(t, err, "PathExists should not error when repo doesn't exist")
|
||||||
|
|
||||||
|
err = git.EnsureRepo(tmp, "test")
|
||||||
|
assert.NoError(t, err, "repo should be created")
|
||||||
|
|
||||||
|
ok, err = git.PathExists(filepath.Join(tmp, "test"))
|
||||||
|
assert.True(t, ok, "repo should exist")
|
||||||
|
assert.NoError(t, err, "EnsureRepo should not error when path exists")
|
||||||
|
|
||||||
|
err = git.EnsureRepo(tmp, "test")
|
||||||
|
assert.NoError(t, err, "repo should already exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRepo(t *testing.T) {
|
||||||
|
tmp := t.TempDir()
|
||||||
|
err := git.EnsureRepo(tmp, "test.git")
|
||||||
|
assert.NoError(t, err, "should create repo")
|
||||||
|
|
||||||
|
repo, err := git.NewRepo(tmp, "test")
|
||||||
|
assert.NoError(t, err, "should init new repo")
|
||||||
|
assert.True(t, repo.Meta.Private, "repo should default to private")
|
||||||
|
|
||||||
|
repo.Meta.Private = false
|
||||||
|
err = repo.SaveMeta()
|
||||||
|
assert.NoError(t, err, "should save repo meta")
|
||||||
|
|
||||||
|
repo, err = git.NewRepo(tmp, "test")
|
||||||
|
assert.NoError(t, err, "should not error when getting existing repo")
|
||||||
|
assert.False(t, repo.Meta.Private, "repo should be public after saving meta")
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package git
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -46,6 +47,16 @@ func (r Repo) SaveMeta() error {
|
||||||
return json.NewEncoder(fi).Encode(r.Meta)
|
return json.NewEncoder(fi).Encode(r.Meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultMeta = func() []byte {
|
||||||
|
b, err := json.Marshal(RepoMeta{
|
||||||
|
Private: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("could not init default meta: %v", err))
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}()
|
||||||
|
|
||||||
func ensureJSONFile(path string) error {
|
func ensureJSONFile(path string) error {
|
||||||
_, err := os.Stat(path)
|
_, err := os.Stat(path)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -59,7 +70,7 @@ func ensureJSONFile(path string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer fi.Close()
|
defer fi.Close()
|
||||||
if _, err := fi.WriteString(`{"private":true}`); err != nil {
|
if _, err := fi.Write(defaultMeta); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue