6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-06 19:50:38 +00:00

Add a run package responsible for running git commands

- Add better git error handling
- Move repo helpers into a separate package
This commit is contained in:
Grzegorz Dlugoszewski
2020-06-26 13:36:58 +02:00
parent 7c5abae165
commit 28b24ec5ce
10 changed files with 482 additions and 399 deletions

View File

@@ -1,30 +1,32 @@
package git
import (
"git-get/pkg/io"
"git-get/pkg/run"
"git-get/pkg/test"
"path"
"testing"
)
// cfgStub represents a gitconfig file but instead of using a global one, it creates a temporary git repo and uses its local gitconfig.
type cfgStub struct {
repo *testRepo
repo *test.Repo
}
func newCfgStub(t *testing.T) *cfgStub {
r := testRepoEmpty(t)
r := test.RepoEmpty(t)
return &cfgStub{
repo: r,
}
}
func (c *cfgStub) Get(key string) string {
cmd := gitCmd(c.repo.path, "config", "--local", key)
out, err := cmd.Output()
out, err := run.Git("config", "--local", key).OnRepo(c.repo.Path()).AndCaptureLine()
if err != nil {
return ""
}
lines := lines(out)
return lines[0]
return out
}
func TestGitConfig(t *testing.T) {
@@ -73,7 +75,7 @@ func TestGitConfig(t *testing.T) {
func makeConfigEmpty(t *testing.T) *cfgStub {
c := newCfgStub(t)
c.repo.writeFile(".git/config", "")
io.Write(path.Join(c.repo.Path(), dotgit, "config"), "")
return c
}
@@ -87,7 +89,7 @@ func makeConfigValid(t *testing.T) *cfgStub {
[gitget]
host = github.com
`
c.repo.writeFile(".git/config", gitconfig)
io.Write(path.Join(c.repo.Path(), dotgit, "config"), gitconfig)
return c
}