mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-06-22 10:02:15 +00:00
feat: prevent default git templates to be created (#12335)
Prevent examples hooks, description file, and other files from the default template to be created during git init. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12335 Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
parent
5b7bcf042c
commit
efa3f4e2b2
3 changed files with 50 additions and 0 deletions
|
|
@ -72,6 +72,8 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
|
|||
}
|
||||
|
||||
cmd := NewCommand(ctx, "init")
|
||||
// Set template to an empty string so that example hooks, and other info files are not created
|
||||
cmd.AddArguments("--template", "")
|
||||
|
||||
if !IsValidObjectFormat(objectFormatName) {
|
||||
return fmt.Errorf("invalid object format: %s", objectFormatName)
|
||||
|
|
|
|||
|
|
@ -117,3 +117,50 @@ func TestCloneCredentials(t *testing.T) {
|
|||
_, err = os.Stat(credentialsFile)
|
||||
require.ErrorIs(t, err, fs.ErrNotExist)
|
||||
}
|
||||
|
||||
func TestInitRepositoryWithNoTemplates(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string // description of this test case
|
||||
// Named input parameters for target function.
|
||||
bare bool
|
||||
objectFormatName string
|
||||
}{
|
||||
{
|
||||
name: "Bare sha1 repo",
|
||||
bare: true,
|
||||
objectFormatName: Sha1ObjectFormat.Name(),
|
||||
},
|
||||
{
|
||||
name: "Non-bare sha1 repo",
|
||||
bare: false,
|
||||
objectFormatName: Sha1ObjectFormat.Name(),
|
||||
},
|
||||
{
|
||||
name: "Bare sha256 repo",
|
||||
bare: true,
|
||||
objectFormatName: Sha256ObjectFormat.Name(),
|
||||
},
|
||||
{
|
||||
name: "Non-bare sha256 repo",
|
||||
bare: false,
|
||||
objectFormatName: Sha256ObjectFormat.Name(),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
repoPath := t.TempDir()
|
||||
|
||||
err := InitRepository(t.Context(), repoPath, tt.bare, tt.objectFormatName)
|
||||
require.NoError(t, err, "couldn't init repository")
|
||||
|
||||
_, err = os.Stat(repoPath + "/hooks")
|
||||
require.ErrorIs(t, err, os.ErrNotExist, "hooks directory shouldn't exist")
|
||||
|
||||
_, err = os.Stat(repoPath + "/description")
|
||||
require.ErrorIs(t, err, os.ErrNotExist, "description file shouldn't exist")
|
||||
|
||||
_, err = os.Stat(repoPath + "/info")
|
||||
require.ErrorIs(t, err, os.ErrNotExist, "info directory shouldn't exist")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
release-notes/12335.md
Normal file
1
release-notes/12335.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
feat: prevent default git templates to be created when initialising a new repository. Migration guide is available in [Admin docs](https://forgejo.org/docs/latest/admin/upgrade/#when-upgrading-from--known-problematic-versions-or-upgrade-paths).
|
||||
Loading…
Add table
Add a link
Reference in a new issue