History

Merge pull request '[gitea] week 15 cherry pick' (#3091) from algernon/forgejo:wcp/week-15 into forgejo

Earl Warren committed 2 years ago

Commit 26fc7c32 parents 7179ae8 9bd261a117 files · +6611 −7217Browse files

Showing the changes to modules/git (3 of 117 files). Show all

Unified · Split

3 files
  1. modules/git/commit_convert_gogit.go +6 −0
  2. modules/git/commit_reader.go +2 −0
  3. modules/git/commit_test.go +67 −0
modules/git/commit_convert_gogit.go+6−0
@@ -47,6 +47,12 @@ func convertPGPSignature(c *object.Commit) *ObjectSignature { · 46 unmodified lines
47 return nil47 return nil
48 }48 }
49 49
50 if c.Encoding != "" && c.Encoding != "UTF-8" {
51 if _, err = fmt.Fprintf(&w, "\nencoding %s\n", c.Encoding); err != nil {
52 return nil
53 }
54 }
55
50 if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {56 if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
51 return nil57 return nil
52 }58 }
modules/git/commit_reader.go+2−0
@@ -84,6 +84,8 @@ readLoop: · 83 unmodified lines
84 commit.Committer = &Signature{}84 commit.Committer = &Signature{}
85 commit.Committer.Decode(data)85 commit.Committer.Decode(data)
86 _, _ = payloadSB.Write(line)86 _, _ = payloadSB.Write(line)
87 case "encoding":
88 _, _ = payloadSB.Write(line)
87 case "gpgsig":89 case "gpgsig":
88 fallthrough90 fallthrough
89 case "gpgsig-sha256": // FIXME: no intertop, so only 1 exists at present.91 case "gpgsig-sha256": // FIXME: no intertop, so only 1 exists at present.
modules/git/commit_test.go+67−0
@@ -125,6 +125,73 @@ empty commit`, commitFromReader.Signature.Payload) · 124 unmodified lines
125 assert.EqualValues(t, commitFromReader, commitFromReader2)125 assert.EqualValues(t, commitFromReader, commitFromReader2)
126}126}
127 127
128func TestCommitWithEncodingFromReader(t *testing.T) {
129 commitString := `feaf4ba6bc635fec442f46ddd4512416ec43c2c2 commit 1074
130tree ca3fad42080dd1a6d291b75acdfc46e5b9b307e5
131parent 47b24e7ab977ed31c5a39989d570847d6d0052af
132author KN4CK3R <admin@oldschoolhack.me> 1711702962 +0100
133committer KN4CK3R <admin@oldschoolhack.me> 1711702962 +0100
134encoding ISO-8859-1
135gpgsig -----BEGIN PGP SIGNATURE-----
136
137 iQGzBAABCgAdFiEE9HRrbqvYxPT8PXbefPSEkrowAa8FAmYGg7IACgkQfPSEkrow
138 Aa9olwv+P0HhtCM6CRvlUmPaqswRsDPNR4i66xyXGiSxdI9V5oJL7HLiQIM7KrFR
139 gizKa2COiGtugv8fE+TKqXKaJx6uJUJEjaBd8E9Af9PrAzjWj+A84lU6/PgPS8hq
140 zOfZraLOEWRH4tZcS+u2yFLu3ez2Wqh1xW5LNy7xqEedMXEFD1HwSJ0+pjacNkzr
141 frp6Asyt7xRI6YmgFJZJoRsS3Ktr6rtKeRL2IErSQQyorOqj6gKrglhrhfG/114j
142 FKB1v4or0WZ1DE8iP2SJZ3n+/K1IuWAINh7MVdb7PndfBPEa+IL+ucNk5uzEE8Jd
143 G8smGxXUeFEt2cP1dj2W8EgAxuA9sTnH9dqI5aRqy5ifDjuya7Emm8sdOUvtGdmn
144 SONRzusmu5n3DgV956REL7x62h7JuqmBz/12HZkr0z0zgXkcZ04q08pSJATX5N1F
145 yN+tWxTsWg+zhDk96d5Esdo9JMjcFvPv0eioo30GAERaz1hoD7zCMT4jgUFTQwgz
146 jw4YcO5u
147 =r3UU
148 -----END PGP SIGNATURE-----
149
150ISO-8859-1`
151
152 sha := &Sha1Hash{0xfe, 0xaf, 0x4b, 0xa6, 0xbc, 0x63, 0x5f, 0xec, 0x44, 0x2f, 0x46, 0xdd, 0xd4, 0x51, 0x24, 0x16, 0xec, 0x43, 0xc2, 0xc2}
153 gitRepo, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare"))
154 assert.NoError(t, err)
155 assert.NotNil(t, gitRepo)
156 defer gitRepo.Close()
157
158 commitFromReader, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString))
159 assert.NoError(t, err)
160 if !assert.NotNil(t, commitFromReader) {
161 return
162 }
163 assert.EqualValues(t, sha, commitFromReader.ID)
164 assert.EqualValues(t, `-----BEGIN PGP SIGNATURE-----
165
166iQGzBAABCgAdFiEE9HRrbqvYxPT8PXbefPSEkrowAa8FAmYGg7IACgkQfPSEkrow
167Aa9olwv+P0HhtCM6CRvlUmPaqswRsDPNR4i66xyXGiSxdI9V5oJL7HLiQIM7KrFR
168gizKa2COiGtugv8fE+TKqXKaJx6uJUJEjaBd8E9Af9PrAzjWj+A84lU6/PgPS8hq
169zOfZraLOEWRH4tZcS+u2yFLu3ez2Wqh1xW5LNy7xqEedMXEFD1HwSJ0+pjacNkzr
170frp6Asyt7xRI6YmgFJZJoRsS3Ktr6rtKeRL2IErSQQyorOqj6gKrglhrhfG/114j
171FKB1v4or0WZ1DE8iP2SJZ3n+/K1IuWAINh7MVdb7PndfBPEa+IL+ucNk5uzEE8Jd
172G8smGxXUeFEt2cP1dj2W8EgAxuA9sTnH9dqI5aRqy5ifDjuya7Emm8sdOUvtGdmn
173SONRzusmu5n3DgV956REL7x62h7JuqmBz/12HZkr0z0zgXkcZ04q08pSJATX5N1F
174yN+tWxTsWg+zhDk96d5Esdo9JMjcFvPv0eioo30GAERaz1hoD7zCMT4jgUFTQwgz
175jw4YcO5u
176=r3UU
177-----END PGP SIGNATURE-----
178`, commitFromReader.Signature.Signature)
179 assert.EqualValues(t, `tree ca3fad42080dd1a6d291b75acdfc46e5b9b307e5
180parent 47b24e7ab977ed31c5a39989d570847d6d0052af
181author KN4CK3R <admin@oldschoolhack.me> 1711702962 +0100
182committer KN4CK3R <admin@oldschoolhack.me> 1711702962 +0100
183encoding ISO-8859-1
184
185ISO-8859-1`, commitFromReader.Signature.Payload)
186 assert.EqualValues(t, "KN4CK3R <admin@oldschoolhack.me>", commitFromReader.Author.String())
187
188 commitFromReader2, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString+"\n\n"))
189 assert.NoError(t, err)
190 commitFromReader.CommitMessage += "\n\n"
191 commitFromReader.Signature.Payload += "\n\n"
192 assert.EqualValues(t, commitFromReader, commitFromReader2)
193}
194
128func TestHasPreviousCommit(t *testing.T) {195func TestHasPreviousCommit(t *testing.T) {
129 bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")196 bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
130 197