mirror of https://git.jolheiser.com/ugit.git
Compare commits
No commits in common. "20a845142722fea74753d64d9488235a85927a7f" and "5809db19f566c4891b4bfe85c5f10e2d467754fe" have entirely different histories.
20a8451427
...
5809db19f5
|
@ -11,7 +11,6 @@ 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"
|
||||||
|
@ -112,7 +111,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ch := make(chan os.Signal, 1)
|
ch := make(chan os.Signal, 1)
|
||||||
signal.Notify(ch, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(ch, os.Kill, os.Interrupt)
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -5,7 +5,6 @@ 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
|
||||||
|
@ -26,7 +25,6 @@ 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
|
||||||
|
@ -48,7 +46,6 @@ 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-L87PnM43gHrDcsRr3wnkB4e1Th2S0LsSwkXuebAFH44=
|
sha256-+pv4dv79+/WUMiPmlK9eebS3NR6aT8q/Cw+MZ5BWoxg=
|
|
@ -1,45 +0,0 @@
|
||||||
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,7 +3,6 @@ package git
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -47,16 +46,6 @@ 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 {
|
||||||
|
@ -70,7 +59,7 @@ func ensureJSONFile(path string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer fi.Close()
|
defer fi.Close()
|
||||||
if _, err := fi.Write(defaultMeta); err != nil {
|
if _, err := fi.WriteString(`{"private":true}`); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue