Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2018-12-21 13:58:59 +0300
committerJacob Vosmaer <jacob@gitlab.com>2018-12-21 13:58:59 +0300
commitf7692ecc8e936c67319e6cf8328badc99871575a (patch)
tree10c9b14c5be0d57e88d7e74bf93286d57410ed6f
parent606874698c0f184e3bd7f4beae9af1b3258828ce (diff)
parent1d5ae61515b70d694499ebaaefb588d655a83ec5 (diff)
Merge branch 'sh-fix-filenames-with-curly-braces' into 'master'
Fix incorrect tree entries retrieved with directories that have curly braces Closes gitlab-ce#46261 See merge request gitlab-org/gitaly!1013
-rw-r--r--changelogs/unreleased/sh-fix-filenames-with-curly-braces.yml5
-rw-r--r--internal/service/commit/tree_entries_helper.go2
-rw-r--r--internal/service/commit/tree_entries_test.go68
3 files changed, 74 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-filenames-with-curly-braces.yml b/changelogs/unreleased/sh-fix-filenames-with-curly-braces.yml
new file mode 100644
index 000000000..45ee9f6f6
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-filenames-with-curly-braces.yml
@@ -0,0 +1,5 @@
+---
+title: Fix incorrect tree entries retrieved with directories that have curly braces
+merge_request: 1013
+author:
+type: fixed
diff --git a/internal/service/commit/tree_entries_helper.go b/internal/service/commit/tree_entries_helper.go
index 1edb74fa2..369b1b2a1 100644
--- a/internal/service/commit/tree_entries_helper.go
+++ b/internal/service/commit/tree_entries_helper.go
@@ -74,7 +74,7 @@ func treeEntries(c *catfile.Batch, revision, path string, rootOid string, recurs
rootOid = rootTreeInfo.Oid
}
- treeEntryInfo, err := c.Info(fmt.Sprintf("%s^{tree}:%s", revision, path))
+ treeEntryInfo, err := c.Info(fmt.Sprintf("%s:%s", revision, path))
if err != nil {
if catfile.IsNotFound(err) {
return nil, nil
diff --git a/internal/service/commit/tree_entries_test.go b/internal/service/commit/tree_entries_test.go
index 48a81a484..f496e49d2 100644
--- a/internal/service/commit/tree_entries_test.go
+++ b/internal/service/commit/tree_entries_test.go
@@ -3,6 +3,8 @@ package commit
import (
"fmt"
"io"
+ "os"
+ "path"
"testing"
"github.com/stretchr/testify/require"
@@ -12,6 +14,72 @@ import (
"google.golang.org/grpc/codes"
)
+func TestSuccessfulGetTreeEntriesWithCurlyBraces(t *testing.T) {
+ server, serverSocketPath := startTestServices(t)
+ defer server.Stop()
+
+ client, conn := newCommitServiceClient(t, serverSocketPath)
+ defer conn.Close()
+
+ testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
+ defer cleanupFn()
+
+ normalFolderName := "issue-46261/folder"
+ curlyFolderName := "issue-46261/{{curly}}"
+ normalFolder := path.Join(testRepoPath, normalFolderName)
+ curlyFolder := path.Join(testRepoPath, curlyFolderName)
+
+ os.MkdirAll(normalFolder, 0755)
+ os.MkdirAll(curlyFolder, 0755)
+
+ testhelper.MustRunCommand(t, nil, "touch", path.Join(normalFolder, "/test1.txt"))
+ testhelper.MustRunCommand(t, nil, "touch", path.Join(curlyFolder, "/test2.txt"))
+
+ testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "add", "--all")
+ testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-m", "Test commit")
+
+ testCases := []struct {
+ description string
+ revision []byte
+ path []byte
+ recursive bool
+ filename []byte
+ }{
+ {
+ description: "with a normal folder",
+ revision: []byte("master"),
+ path: []byte(normalFolderName),
+ filename: []byte("issue-46261/folder/test1.txt"),
+ },
+ {
+ description: "with a folder with curly braces",
+ revision: []byte("master"),
+ path: []byte(curlyFolderName),
+ filename: []byte("issue-46261/{{curly}}/test2.txt"),
+ },
+ }
+
+ for _, testCase := range testCases {
+ request := &gitalypb.GetTreeEntriesRequest{
+ Repository: testRepo,
+ Revision: []byte("HEAD"),
+ Path: testCase.path,
+ Recursive: testCase.recursive,
+ }
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ c, err := client.GetTreeEntries(ctx, request)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ fetchedEntries := getTreeEntriesFromTreeEntryClient(t, c)
+ require.Equal(t, 1, len(fetchedEntries))
+ require.Equal(t, testCase.filename, fetchedEntries[0].FlatPath)
+ }
+}
+
func TestSuccessfulGetTreeEntries(t *testing.T) {
// Force entries to be sliced to test that behaviour
oldMaxTreeEntries := maxTreeEntries