MCPcopy
hub / github.com/go-git/go-git / TestSetPackedRef

Method TestSetPackedRef

storage/filesystem/dotgit/dotgit_test.go:1069–1125  ·  view source on GitHub ↗

Checks that setting a reference that has been packed and checking its old value is successful

(c *C)

Source from the content-addressed store, hash-verified

1067
1068// Checks that setting a reference that has been packed and checking its old value is successful
1069func (s *SuiteDotGit) TestSetPackedRef(c *C) {
1070 fs := s.TemporalFilesystem(c)
1071
1072 dir := New(fs)
1073
1074 err := dir.SetRef(plumbing.NewReferenceFromStrings(
1075 "refs/heads/foo",
1076 "e8d3ffab552895c19b9fcf7aa264d277cde33881",
1077 ), nil)
1078 c.Assert(err, IsNil)
1079
1080 refs, err := dir.Refs()
1081 c.Assert(err, IsNil)
1082 c.Assert(refs, HasLen, 1)
1083 looseCount, err := dir.CountLooseRefs()
1084 c.Assert(err, IsNil)
1085 c.Assert(looseCount, Equals, 1)
1086
1087 err = dir.PackRefs()
1088 c.Assert(err, IsNil)
1089
1090 // Make sure the refs are still there, but no longer loose.
1091 refs, err = dir.Refs()
1092 c.Assert(err, IsNil)
1093 c.Assert(refs, HasLen, 1)
1094 looseCount, err = dir.CountLooseRefs()
1095 c.Assert(err, IsNil)
1096 c.Assert(looseCount, Equals, 0)
1097
1098 ref, err := dir.Ref("refs/heads/foo")
1099 c.Assert(err, IsNil)
1100 c.Assert(ref, NotNil)
1101 c.Assert(ref.Hash().String(), Equals, "e8d3ffab552895c19b9fcf7aa264d277cde33881")
1102
1103 // Attempt to update the reference using an invalid old reference value
1104 err = dir.SetRef(plumbing.NewReferenceFromStrings(
1105 "refs/heads/foo",
1106 "b8d3ffab552895c19b9fcf7aa264d277cde33881",
1107 ), plumbing.NewReferenceFromStrings(
1108 "refs/heads/foo",
1109 "e8d3ffab552895c19b9fcf7aa264d277cde33882",
1110 ))
1111 c.Assert(err, Equals, storage.ErrReferenceHasChanged)
1112
1113 // Now update the reference and it should pass
1114 err = dir.SetRef(plumbing.NewReferenceFromStrings(
1115 "refs/heads/foo",
1116 "b8d3ffab552895c19b9fcf7aa264d277cde33881",
1117 ), plumbing.NewReferenceFromStrings(
1118 "refs/heads/foo",
1119 "e8d3ffab552895c19b9fcf7aa264d277cde33881",
1120 ))
1121 c.Assert(err, IsNil)
1122 looseCount, err = dir.CountLooseRefs()
1123 c.Assert(err, IsNil)
1124 c.Assert(looseCount, Equals, 1)
1125}
1126

Callers

nothing calls this directly

Calls 10

TemporalFilesystemMethod · 0.95
NewReferenceFromStringsFunction · 0.92
SetRefMethod · 0.80
RefsMethod · 0.80
RefMethod · 0.80
NewFunction · 0.70
CountLooseRefsMethod · 0.65
PackRefsMethod · 0.65
StringMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected