Skip to content
Snippets Groups Projects
Verified Commit dd2ec883 authored by Justin Tobler's avatar Justin Tobler Committed by GitLab
Browse files

Merge branch 'jc/fix-tree-add-16-7' into '16-7-stable'

Backport jc/fix-add-tree-entry into 16-7-stable

See merge request !6675



Merged-by: default avatarJustin Tobler <jtobler@gitlab.com>
Approved-by: default avatarJustin Tobler <jtobler@gitlab.com>
Co-authored-by: John Cai's avatarJohn Cai <jcai@gitlab.com>
parents 0a96e0b5 b05b9d38
No related branches found
No related tags found
1 merge request!6675Backport jc/fix-add-tree-entry into 16-7-stable
Pipeline #1173928502 passed
......@@ -217,16 +217,14 @@ Loop:
continue Loop
}
// If we get here, that means we didn't find any directories to
// recurse into, which means we need to create a brand new
// tree
if firstComponent == filepath.Base(path) {
// If secondComponent is empty, the end of the specified path has been reached.
// The new entry is added to the current tree and the operation completes.
if secondComponent == "" {
currentTree.OID = ""
currentTree.Entries = append(
currentTree.Entries,
&newEntry,
)
return nil
}
......@@ -236,12 +234,11 @@ Loop:
Path: firstComponent,
})
// Empty out the OID because we've modified this tree, and will
// need to write a new one. Write() will write a new tree object
// if it sees that the OID is empty.
currentTree.OID = ""
currentTree = currentTree.Entries[len(currentTree.Entries)-1]
if secondComponent == "" {
return nil
}
}
}
......
......@@ -1795,6 +1795,58 @@ func TestTreeEntry_Add(t *testing.T) {
},
expectedErr: ErrEntryExists,
},
{
desc: "add nested directory with same name",
tree: TreeEntry{
OID: "abc",
Type: Tree,
Mode: "040000",
},
pathToAdd: "dirA/file1/dirA/file1",
entryToAdd: TreeEntry{
OID: "d1",
Type: Blob,
Mode: "100644",
Path: "file1",
},
expectedTree: TreeEntry{
OID: "",
Type: Tree,
Mode: "040000",
Entries: []*TreeEntry{
{
OID: "",
Type: Tree,
Mode: "040000",
Path: "dirA",
Entries: []*TreeEntry{
{
OID: "",
Mode: "040000",
Type: Tree,
Path: "file1",
Entries: []*TreeEntry{
{
OID: "",
Type: Tree,
Mode: "040000",
Path: "dirA",
Entries: []*TreeEntry{
{
OID: "d1",
Type: Blob,
Mode: "100644",
Path: "file1",
},
},
},
},
},
},
},
},
},
},
}
for _, tc := range testCases {
......
......@@ -248,6 +248,22 @@ func testUserCommitFiles(t *testing.T, ctx context.Context) {
},
},
},
{
desc: "create file in directory",
steps: []step{
{
actions: []*gitalypb.UserCommitFilesRequest{
createFileHeaderRequest("folder-1/filename/folder-1/filename"),
actionContentRequest("content-1"),
},
repoCreated: true,
branchCreated: true,
treeEntries: []gittest.TreeEntry{
{Mode: DefaultMode, Path: "folder-1/filename/folder-1/filename", Content: "content-1"},
},
},
},
},
{
desc: "create file with unclean path",
steps: []step{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment