Commit ba1d6d7c authored by Phil Hughes's avatar Phil Hughes

Fixed IDE file list when files have same name but different paths

Closes #5092
parent 6d49d141
...@@ -121,8 +121,8 @@ export const getTreeEntry = (store, treeId, path) => { ...@@ -121,8 +121,8 @@ export const getTreeEntry = (store, treeId, path) => {
return fileList ? fileList.find(file => file.path === path) : null; return fileList ? fileList.find(file => file.path === path) : null;
}; };
export const findEntry = (tree, type, name) => tree.find( export const findEntry = (tree, type, name, prop = 'name') => tree.find(
f => f.type === type && f.name === name, f => f.type === type && f[prop] === name,
); );
export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path); export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path);
...@@ -163,7 +163,7 @@ export const createOrMergeEntry = ({ projectId, ...@@ -163,7 +163,7 @@ export const createOrMergeEntry = ({ projectId,
level, level,
state }) => { state }) => {
if (state.changedFiles.length) { if (state.changedFiles.length) {
const foundChangedFile = findEntry(state.changedFiles, type, entry.name); const foundChangedFile = findEntry(state.changedFiles, type, entry.path, 'path');
if (foundChangedFile) { if (foundChangedFile) {
return foundChangedFile; return foundChangedFile;
...@@ -171,7 +171,7 @@ export const createOrMergeEntry = ({ projectId, ...@@ -171,7 +171,7 @@ export const createOrMergeEntry = ({ projectId,
} }
if (state.openFiles.length) { if (state.openFiles.length) {
const foundOpenFile = findEntry(state.openFiles, type, entry.name); const foundOpenFile = findEntry(state.openFiles, type, entry.path, 'path');
if (foundOpenFile) { if (foundOpenFile) {
return foundOpenFile; return foundOpenFile;
......
---
title: Fixed IDE file list when multiple files have same name but different paths
merge_request:
author:
type: fixed
...@@ -426,5 +426,63 @@ describe('Multi-file store tree actions', () => { ...@@ -426,5 +426,63 @@ describe('Multi-file store tree actions', () => {
done(); done();
}).catch(done.fail); }).catch(done.fail);
}); });
it('does not add changed file with same name but different path', (done) => {
const f = file('openedFile');
const tree = {
tree: [],
};
const data = {
trees: [{ name: 'tree' }],
submodules: [{ name: 'submodule' }],
blobs: [f],
};
store.state.changedFiles.push({
...f,
type: 'blob',
path: `src/${f.name}`,
changed: true,
});
store.dispatch('updateDirectoryData', {
data,
tree,
clearTree: false,
}).then(() => {
expect(tree.tree[2].changed).toBeFalsy();
done();
}).catch(done.fail);
});
it('does not add opened file with same name but different path', (done) => {
const f = file('openedFile');
const tree = {
tree: [],
};
const data = {
trees: [{ name: 'tree' }],
submodules: [{ name: 'submodule' }],
blobs: [f],
};
store.state.openFiles.push({
...f,
type: 'blob',
path: `src/${f.name}`,
opened: true,
});
store.dispatch('updateDirectoryData', {
data,
tree,
clearTree: false,
}).then(() => {
expect(tree.tree[2].opened).toBeFalsy();
done();
}).catch(done.fail);
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment