Commit 6ac71623 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ide-delete-new-files-state' into 'master'

Fixed deleting new files creating wrong state in IDE

Closes #50255

See merge request gitlab-org/gitlab-ce!21225
parents a2d647b1 177a5e69
...@@ -200,6 +200,7 @@ export default { ...@@ -200,6 +200,7 @@ export default {
}, },
[types.DELETE_ENTRY](state, path) { [types.DELETE_ENTRY](state, path) {
const entry = state.entries[path]; const entry = state.entries[path];
const { tempFile = false } = entry;
const parent = entry.parentPath const parent = entry.parentPath
? state.entries[entry.parentPath] ? state.entries[entry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; : state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
...@@ -209,8 +210,12 @@ export default { ...@@ -209,8 +210,12 @@ export default {
parent.tree = parent.tree.filter(f => f.path !== entry.path); parent.tree = parent.tree.filter(f => f.path !== entry.path);
if (entry.type === 'blob') { if (entry.type === 'blob') {
if (tempFile) {
state.changedFiles = state.changedFiles.filter(f => f.path !== path);
} else {
state.changedFiles = state.changedFiles.concat(entry); state.changedFiles = state.changedFiles.concat(entry);
} }
}
}, },
[types.RENAME_ENTRY](state, { path, name, entryPath = null }) { [types.RENAME_ENTRY](state, { path, name, entryPath = null }) {
const oldEntry = state.entries[entryPath || path]; const oldEntry = state.entries[entryPath || path];
......
---
title: Fixed IDE deleting new files creating wrong state
merge_request:
author:
type: fixed
...@@ -213,6 +213,33 @@ describe('Multi-file store mutations', () => { ...@@ -213,6 +213,33 @@ describe('Multi-file store mutations', () => {
expect(localState.changedFiles).toEqual([localState.entries.filePath]); expect(localState.changedFiles).toEqual([localState.entries.filePath]);
}); });
it('does not add tempFile into changedFiles', () => {
localState.entries.filePath = {
deleted: false,
type: 'blob',
tempFile: true,
};
mutations.DELETE_ENTRY(localState, 'filePath');
expect(localState.changedFiles).toEqual([]);
});
it('removes tempFile from changedFiles when deleted', () => {
localState.entries.filePath = {
path: 'filePath',
deleted: false,
type: 'blob',
tempFile: true,
};
localState.changedFiles.push({ ...localState.entries.filePath });
mutations.DELETE_ENTRY(localState, 'filePath');
expect(localState.changedFiles).toEqual([]);
});
}); });
describe('UPDATE_FILE_AFTER_COMMIT', () => { describe('UPDATE_FILE_AFTER_COMMIT', () => {
......
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