aboutsummaryrefslogtreecommitdiffstats
path: root/common_test.go
diff options
context:
space:
mode:
authorArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-05-24 15:17:02 +1000
committerArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-05-24 15:17:02 +1000
commitcdba5330cd205312443e8553f434829c4c5e66ee (patch)
tree034e45271df32054b7994356d8358e9ac2f33f36 /common_test.go
parent84d9be20ca15d29bebc629e5b6f29dab78cc69ba (diff)
downloadgo-git-cdba5330cd205312443e8553f434829c4c5e66ee.tar.gz
git: Fix fetching after shallow clone. Fixes #305
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
Diffstat (limited to 'common_test.go')
-rw-r--r--common_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/common_test.go b/common_test.go
index 3311a17..7f9b84b 100644
--- a/common_test.go
+++ b/common_test.go
@@ -3,10 +3,12 @@ package git
import (
"os"
"testing"
+ "time"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/plumbing/format/packfile"
+ "github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/storage/filesystem"
"github.com/go-git/go-git/v5/storage/memory"
@@ -212,3 +214,36 @@ func AssertReferencesMissing(c *C, r *Repository, expected []string) {
c.Assert(err, Equals, plumbing.ErrReferenceNotFound)
}
}
+
+func CommitNewFile(c *C, repo *Repository, fileName string) plumbing.Hash {
+ wt, err := repo.Worktree()
+ c.Assert(err, IsNil)
+
+ fd, err := wt.Filesystem.Create(fileName)
+ c.Assert(err, IsNil)
+
+ _, err = fd.Write([]byte("# test file"))
+ c.Assert(err, IsNil)
+
+ err = fd.Close()
+ c.Assert(err, IsNil)
+
+ _, err = wt.Add(fileName)
+ c.Assert(err, IsNil)
+
+ sha, err := wt.Commit("test commit", &CommitOptions{
+ Author: &object.Signature{
+ Name: "test",
+ Email: "test@example.com",
+ When: time.Now(),
+ },
+ Committer: &object.Signature{
+ Name: "test",
+ Email: "test@example.com",
+ When: time.Now(),
+ },
+ })
+ c.Assert(err, IsNil)
+
+ return sha
+}