Commit 95bacb06 authored by Himanshu Kapoor's avatar Himanshu Kapoor

Clear staged changes _before_ redirection

Any local changes in WebIDE should be cleared _before_ redirecting
to the new merge request page. Earlier, it was happening just after
redirection, which causes onbeforeunload event to trigger and warns the
user that his unsaved changes will be lost, when in fact there are no
unsaved changes at this point.

The test for this case was falsely passing. I have modified it to
ensure that it always fails in the absence of this change.
parent d9117a45
...@@ -152,6 +152,14 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo ...@@ -152,6 +152,14 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
branch: getters.branchName, branch: getters.branchName,
}) })
.then(() => { .then(() => {
commit(rootTypes.CLEAR_STAGED_CHANGES, null, { root: true });
commit(rootTypes.CLEAR_REPLACED_FILES, null, { root: true });
setTimeout(() => {
commit(rootTypes.SET_LAST_COMMIT_MSG, '', { root: true });
}, 5000);
if (state.shouldCreateMR) { if (state.shouldCreateMR) {
const { currentProject } = rootGetters; const { currentProject } = rootGetters;
const targetBranch = getters.isCreatingNewBranch const targetBranch = getters.isCreatingNewBranch
...@@ -164,14 +172,6 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo ...@@ -164,14 +172,6 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
{ root: true }, { root: true },
); );
} }
commit(rootTypes.CLEAR_STAGED_CHANGES, null, { root: true });
commit(rootTypes.CLEAR_REPLACED_FILES, null, { root: true });
setTimeout(() => {
commit(rootTypes.SET_LAST_COMMIT_MSG, '', { root: true });
}, 5000);
}) })
.then(() => { .then(() => {
if (rootGetters.lastOpenedFile) { if (rootGetters.lastOpenedFile) {
......
---
title: 'Fix Issue: WebIDE asks for confirmation to leave the page when committing
and creating a new MR'
merge_request: 17671
author:
type: fixed
...@@ -473,18 +473,16 @@ describe('IDE commit module actions', () => { ...@@ -473,18 +473,16 @@ describe('IDE commit module actions', () => {
}); });
it('resets changed files before redirecting', done => { it('resets changed files before redirecting', done => {
visitUrl = visitUrl.and.callFake(() => {
expect(store.state.stagedFiles.length).toBe(0);
done();
});
spyOn(eventHub, '$on'); spyOn(eventHub, '$on');
store.state.commit.commitAction = '3'; store.state.commit.commitAction = '3';
store store.dispatch('commit/commitChanges').catch(done.fail);
.dispatch('commit/commitChanges')
.then(() => {
expect(store.state.stagedFiles.length).toBe(0);
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