diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-27 12:39:10 -0800 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-11-27 13:34:59 -0800 |
commit | d3f5eaf71b01b9f7f823470ac22958bd5fabbbcd (patch) | |
tree | c7c61bc5bd937fe497758222b442e5171f36a09b /remote_test.go | |
parent | 77482f9ac6095ad4a863e348ab1ac9bf9ab2e0b2 (diff) | |
download | go-git-d3f5eaf71b01b9f7f823470ac22958bd5fabbbcd.tar.gz |
remote: add test for non-force, fast-forward fetching
Diffstat (limited to 'remote_test.go')
-rw-r--r-- | remote_test.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/remote_test.go b/remote_test.go index 3452ddf..dff1499 100644 --- a/remote_test.go +++ b/remote_test.go @@ -308,6 +308,48 @@ func (s *RemoteSuite) doTestFetchNoErrAlreadyUpToDate(c *C, url string) { c.Assert(err, Equals, NoErrAlreadyUpToDate) } +func (s *RemoteSuite) TestFetchFastForward(c *C) { + r := newRemote(memory.NewStorage(), &config.RemoteConfig{ + URLs: []string{s.GetBasicLocalRepositoryURL()}, + }) + + s.testFetch(c, r, &FetchOptions{ + RefSpecs: []config.RefSpec{ + config.RefSpec("+refs/heads/master:refs/heads/master"), + }, + }, []*plumbing.Reference{ + plumbing.NewReferenceFromStrings("refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), + }) + + // First make sure that we error correctly when a force is required. + err := r.Fetch(&FetchOptions{ + RefSpecs: []config.RefSpec{ + config.RefSpec("refs/heads/branch:refs/heads/master"), + }, + }) + c.Assert(err, Equals, ErrForceNeeded) + + // And that forcing it fixes the problem. + err = r.Fetch(&FetchOptions{ + RefSpecs: []config.RefSpec{ + config.RefSpec("+refs/heads/branch:refs/heads/master"), + }, + }) + c.Assert(err, IsNil) + + // Now test that a fast-forward, non-force fetch works. + r.s.SetReference(plumbing.NewReferenceFromStrings( + "refs/heads/master", "918c48b83bd081e863dbe1b80f8998f058cd8294", + )) + s.testFetch(c, r, &FetchOptions{ + RefSpecs: []config.RefSpec{ + config.RefSpec("refs/heads/master:refs/heads/master"), + }, + }, []*plumbing.Reference{ + plumbing.NewReferenceFromStrings("refs/heads/master", "6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), + }) +} + func (s *RemoteSuite) TestString(c *C) { r := newRemote(nil, &config.RemoteConfig{ Name: "foo", |