aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--example_test.go10
-rw-r--r--repository.go15
-rw-r--r--worktree_status.go4
-rw-r--r--worktree_test.go38
5 files changed, 62 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 2d83068..038dd9f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
coverage.out
+*~
+coverage.txt
+profile.out
diff --git a/example_test.go b/example_test.go
index e9d8e8b..ef7e3d3 100644
--- a/example_test.go
+++ b/example_test.go
@@ -24,12 +24,18 @@ func ExampleClone() {
// Clones the repository into the worktree (fs) and storer all the .git
// content into the storer
- _, _ = git.Clone(storer, fs, &git.CloneOptions{
+ _, err := git.Clone(storer, fs, &git.CloneOptions{
URL: "https://github.com/git-fixtures/basic.git",
})
+ if err != nil {
+ log.Fatal(err)
+ }
// Prints the content of the CHANGELOG file from the cloned repository
- changelog, _ := fs.Open("CHANGELOG")
+ changelog, err := fs.Open("CHANGELOG")
+ if err != nil {
+ log.Fatal(err)
+ }
io.Copy(os.Stdout, changelog)
// Output: Initial changelog
diff --git a/repository.go b/repository.go
index 928ad9d..717381b 100644
--- a/repository.go
+++ b/repository.go
@@ -24,6 +24,9 @@ import (
"gopkg.in/src-d/go-billy.v4/osfs"
)
+// GitDirName this is a special folder where all the git stuff is.
+const GitDirName = ".git"
+
var (
// ErrBranchExists an error stating the specified branch already exists
ErrBranchExists = errors.New("branch already exists")
@@ -113,12 +116,12 @@ func createDotGitFile(worktree, storage billy.Filesystem) error {
path = storage.Root()
}
- if path == ".git" {
+ if path == GitDirName {
// not needed, since the folder is the default place
return nil
}
- f, err := worktree.Create(".git")
+ f, err := worktree.Create(GitDirName)
if err != nil {
return err
}
@@ -214,7 +217,7 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
dot = osfs.New(path)
} else {
wt = osfs.New(path)
- dot, _ = wt.Chroot(".git")
+ dot, _ = wt.Chroot(GitDirName)
}
s, err := filesystem.NewStorage(dot)
@@ -265,7 +268,7 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
var fi os.FileInfo
for {
fs = osfs.New(path)
- fi, err = fs.Stat(".git")
+ fi, err = fs.Stat(GitDirName)
if err == nil {
// no error; stop
break
@@ -288,7 +291,7 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
}
if fi.IsDir() {
- dot, err = fs.Chroot(".git")
+ dot, err = fs.Chroot(GitDirName)
return dot, fs, err
}
@@ -301,7 +304,7 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
}
func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Filesystem, err error) {
- f, err := fs.Open(".git")
+ f, err := fs.Open(GitDirName)
if err != nil {
return nil, err
}
diff --git a/worktree_status.go b/worktree_status.go
index 2cac78e..b5f2381 100644
--- a/worktree_status.go
+++ b/worktree_status.go
@@ -300,6 +300,10 @@ func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string)
var a bool
if file.IsDir() {
+ if file.Name() == GitDirName {
+ // ignore special git directory
+ continue
+ }
a, err = w.doAddDirectory(idx, s, name)
} else {
a, _, err = w.doAddFile(idx, s, name)
diff --git a/worktree_test.go b/worktree_test.go
index b3e0a1a..05a205a 100644
--- a/worktree_test.go
+++ b/worktree_test.go
@@ -3,12 +3,14 @@ package git
import (
"bytes"
"context"
+ "errors"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"runtime"
"testing"
+ "time"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
@@ -1833,3 +1835,39 @@ func (s *WorktreeSuite) TestGrep(c *C) {
}
}
}
+
+func (s *WorktreeSuite) TestAddAndCommit(c *C) {
+ dir, err := ioutil.TempDir("", "plain-repo")
+ c.Assert(err, IsNil)
+ defer os.RemoveAll(dir)
+
+ repo, err := PlainInit(dir, false)
+ c.Assert(err, IsNil)
+
+ w, err := repo.Worktree()
+ c.Assert(err, IsNil)
+
+ _, err = w.Add(".")
+ c.Assert(err, IsNil)
+
+ w.Commit("Test Add And Commit", &CommitOptions{Author: &object.Signature{
+ Name: "foo",
+ Email: "foo@foo.foo",
+ When: time.Now(),
+ }})
+
+ iter, err := w.r.Log(&LogOptions{})
+ c.Assert(err, IsNil)
+ err = iter.ForEach(func(c *object.Commit) error {
+ files, err := c.Files()
+ if err != nil {
+ return err
+ }
+
+ err = files.ForEach(func(f *object.File) error {
+ return errors.New("Expected no files, got at least 1")
+ })
+ return err
+ })
+ c.Assert(err, IsNil)
+}