aboutsummaryrefslogtreecommitdiffstats
path: root/common_test.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-05-24 20:12:55 +0100
committerGitHub <noreply@github.com>2023-05-24 20:12:55 +0100
commitb98b813a17d32f4fa29a3ef2e9f4c38c5a97b440 (patch)
tree034e45271df32054b7994356d8358e9ac2f33f36 /common_test.go
parent84d9be20ca15d29bebc629e5b6f29dab78cc69ba (diff)
parentcdba5330cd205312443e8553f434829c4c5e66ee (diff)
downloadgo-git-b98b813a17d32f4fa29a3ef2e9f4c38c5a97b440.tar.gz
Merge pull request #778 from AriehSchneier/fix-fetch-after-shallow-v2
git: Fix fetching after shallow clone. Fixes #305
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
+}