func gitFixture(tree *fixtures.Tree) (res *git.Git, err error) { res = &git.Git{lists.NewMapper(tree.CWD, tree.CWD)} if _, err = res.Run("init"); err != nil { return } if _, err = res.Run("add", "-A"); err != nil { return } if _, err = res.Run("commit", "-m", "master1"); err != nil { return } if _, err = res.Run("checkout", "-b", "other"); err != nil { return } os.MkdirAll(filepath.Join(tree.CWD, "in-other"), 0755) fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "in-other", "blob.bin"), 1670) fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "one", "file-one.bin"), 170) fixtures.MakeNamedBLOB(filepath.Join(tree.CWD, "two", "file-four with spaces.bin"), 170) if _, err = res.Run("add", "-A"); err != nil { return } if _, err = res.Run("commit", "-m", "other1"); err != nil { return } if _, err = res.Run("checkout", "master"); err != nil { return } return }
func Test_Mapper_FromRoot(t *testing.T) { root := "/home/user" cwd := "/home/user/wd" mapper := lists.NewMapper(cwd, root) res, err := mapper.FromRoot("wd/a1/b", "wd/a2") assert.NoError(t, err) assert.Equal(t, []string{"a1/b", "a2"}, res) }
// New git in given root. func NewGit(cwd string) (res *Git, err error) { if cwd == "" { if cwd, err = os.Getwd(); err != nil { return } } raw, err := execCommand("git", "-C", cwd, "rev-parse", "--show-toplevel").Output() if err != nil { return } root := strings.TrimSpace(string(raw)) res = &Git{lists.NewMapper(cwd, root)} return }