mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2026-05-13 06:20:24 +00:00
fix(ui): allow creating files with name starting with dash (#12214)
Closes: #12204
The underlying git option was already changed in git 2.0.0 to use format `<mode>,<object>,<path>`. See ec160ae12b.
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12214
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Robert Wolff <mahlzahn@posteo.de>
Co-committed-by: Robert Wolff <mahlzahn@posteo.de>
This commit is contained in:
parent
9c4fc72985
commit
33d6ecfca6
2 changed files with 12 additions and 2 deletions
|
|
@ -189,7 +189,7 @@ func (t *TemporaryUploadRepository) HashObject(content io.Reader) (string, error
|
|||
|
||||
// AddObjectToIndex adds the provided object hash to the index with the provided mode and path
|
||||
func (t *TemporaryUploadRepository) AddObjectToIndex(mode, objectHash, objectPath string) error {
|
||||
if _, _, err := git.NewCommand(t.ctx, "update-index", "--add", "--replace", "--cacheinfo").AddDynamicArguments(mode, objectHash, objectPath).RunStdString(&git.RunOpts{Dir: t.basePath}); err != nil {
|
||||
if _, _, err := git.NewCommand(t.ctx, "update-index", "--add", "--replace", "--cacheinfo").AddDynamicArguments(mode + "," + objectHash + "," + objectPath).RunStdString(&git.RunOpts{Dir: t.basePath}); err != nil {
|
||||
stderr := err.Error()
|
||||
if matched, _ := regexp.MatchString(".*Invalid path '.*", stderr); matched {
|
||||
return models.ErrFilePathInvalid{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRemoveFilesFromIndexSha256(t *testing.T) {
|
||||
func TestTemporaryUploadRepositoryRemoveFilesFromIndexSha256(t *testing.T) {
|
||||
if git.CheckGitVersionAtLeast("2.42") != nil {
|
||||
t.Skip("skipping because installed Git version doesn't support SHA256")
|
||||
}
|
||||
|
|
@ -26,3 +26,13 @@ func TestRemoveFilesFromIndexSha256(t *testing.T) {
|
|||
require.NoError(t, temp.Init("sha256"))
|
||||
require.NoError(t, temp.RemoveFilesFromIndex("README.md"))
|
||||
}
|
||||
|
||||
func TestTemporaryUploadRepositoryAddObjectToIndex(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
temp, err := NewTemporaryUploadRepository(db.DefaultContext, repo)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, temp.Init("sha1"))
|
||||
require.NoError(t, temp.AddObjectToIndex("100644", "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", "--test"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue