Commit ab72cfc3 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 483a66c0
......@@ -191,25 +191,34 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) =
dispatch('restoreTree', file.parentPath);
}
commit(types.DISCARD_FILE_CHANGES, path);
commit(types.REMOVE_FILE_FROM_CHANGED, path);
if (file.prevPath) {
dispatch('discardFileChanges', file.prevPath);
}
if (file.tempFile || file.prevPath) {
dispatch('closeFile', file);
if (file.tempFile && file.opened) {
commit(types.TOGGLE_FILE_OPEN, path);
} else if (getters.activeFile && file.path === getters.activeFile.path) {
dispatch('updateDelayViewerUpdated', true)
.then(() => {
router.push(`/project${file.url}`);
})
.catch(e => {
throw e;
if (file.tempFile) {
dispatch('deleteEntry', file.path);
} else {
dispatch('renameEntry', {
path: file.path,
name: file.prevName,
parentPath: file.prevParentPath,
});
}
} else {
commit(types.DISCARD_FILE_CHANGES, path);
if (getters.activeFile && file.path === getters.activeFile.path) {
dispatch('updateDelayViewerUpdated', true)
.then(() => {
router.push(`/project${file.url}`);
})
.catch(e => {
throw e;
});
}
}
commit(types.REMOVE_FILE_FROM_CHANGED, path);
eventHub.$emit(`editor.update.model.new.content.${file.key}`, file.content);
eventHub.$emit(`editor.update.model.dispose.unstaged-${file.key}`, file.content);
};
......
---
title: Fix "Discard" for newly-created and renamed files
merge_request: 21905
author:
type: fixed
......@@ -581,11 +581,13 @@ describe('IDE store file actions', () => {
jest.spyOn(eventHub, '$on').mockImplementation(() => {});
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
tmpFile = file();
tmpFile = file('tempFile');
tmpFile.content = 'testing';
store.state.changedFiles.push(tmpFile);
store.state.entries[tmpFile.path] = tmpFile;
jest.spyOn(store, 'dispatch');
});
it('resets file content', done => {
......@@ -610,33 +612,35 @@ describe('IDE store file actions', () => {
.catch(done.fail);
});
it('closes temp file', done => {
it('closes temp file and deletes it', () => {
tmpFile.tempFile = true;
tmpFile.opened = true;
tmpFile.parentPath = 'parentFile';
store.state.entries.parentFile = file('parentFile');
store
.dispatch('discardFileChanges', tmpFile.path)
.then(() => {
expect(tmpFile.opened).toBeFalsy();
actions.discardFileChanges(store, tmpFile.path);
done();
})
.catch(done.fail);
expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile);
expect(store.dispatch).toHaveBeenCalledWith('deleteEntry', tmpFile.path);
});
it('does not re-open a closed temp file', done => {
tmpFile.tempFile = true;
it('renames the file to its original name and closes it if it was open', () => {
Object.assign(tmpFile, {
prevPath: 'parentPath/old_name',
prevName: 'old_name',
prevParentPath: 'parentPath',
});
expect(tmpFile.opened).toBeFalsy();
store.state.entries.parentPath = file('parentPath');
store
.dispatch('discardFileChanges', tmpFile.path)
.then(() => {
expect(tmpFile.opened).toBeFalsy();
actions.discardFileChanges(store, tmpFile.path);
done();
})
.catch(done.fail);
expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile);
expect(store.dispatch).toHaveBeenCalledWith('renameEntry', {
path: 'tempFile',
name: 'old_name',
parentPath: 'parentPath',
});
});
it('pushes route for active file', done => {
......
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