diff options
author | Paul Slaughter <pslaughter@gitlab.com> | 2019-06-17 12:53:58 -0500 |
---|---|---|
committer | Paul Slaughter <pslaughter@gitlab.com> | 2019-06-17 14:04:35 -0500 |
commit | 894ad6f6e983cb17c7b63b4185c63a42b6203a4f (patch) | |
tree | bd3990e5b4fe0e9521287bf0c327925a82084c50 /app/assets/javascripts | |
parent | 89a89b3230717920410de6fb6d6b7152ef41a03e (diff) | |
download | gitlab-ce-894ad6f6e983cb17c7b63b4185c63a42b6203a4f.tar.gz |
Fix IDE commit to use start_ref59023-fix-web-ide-creating-branches-off-new-commits
**Why?**
The branch HEAD could be changed since the
IDE was opened. This leads to user's unintentionally
creating commits that overwrite other changes.
https://gitlab.com/gitlab-org/gitlab-ce/issues/59023
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r-- | app/assets/javascripts/ide/services/index.js | 8 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/modules/commit/actions.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/utils.js | 11 |
3 files changed, 17 insertions, 3 deletions
diff --git a/app/assets/javascripts/ide/services/index.js b/app/assets/javascripts/ide/services/index.js index ba33b6826d6..840761f68db 100644 --- a/app/assets/javascripts/ide/services/index.js +++ b/app/assets/javascripts/ide/services/index.js @@ -56,7 +56,13 @@ export default { return Api.branchSingle(projectId, currentBranchId); }, commit(projectId, payload) { - return Api.commitMultiple(projectId, payload); + // Currently the `commit` endpoint does not support `start_sha` so we + // have to make the request in the FE. This is not ideal and will be + // resolved soon. https://gitlab.com/gitlab-org/gitlab-ce/issues/59023 + const { branch, start_sha: ref } = payload; + const branchPromise = ref ? Api.createBranch(projectId, { ref, branch }) : Promise.resolve(); + + return branchPromise.then(() => Api.commitMultiple(projectId, payload)); }, getFiles(projectUrl, branchId) { const url = `${projectUrl}/files/${branchId}`; diff --git a/app/assets/javascripts/ide/stores/modules/commit/actions.js b/app/assets/javascripts/ide/stores/modules/commit/actions.js index 51062f092ad..ff1255ce749 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/actions.js +++ b/app/assets/javascripts/ide/stores/modules/commit/actions.js @@ -142,6 +142,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo getters, state, rootState, + rootGetters, }); return service.commit(rootState.currentProjectId, payload); diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js index bcc9ca60d9b..4e7a8765abe 100644 --- a/app/assets/javascripts/ide/stores/utils.js +++ b/app/assets/javascripts/ide/stores/utils.js @@ -135,7 +135,14 @@ export const getCommitFiles = stagedFiles => }); }, []); -export const createCommitPayload = ({ branch, getters, newBranch, state, rootState }) => ({ +export const createCommitPayload = ({ + branch, + getters, + newBranch, + state, + rootState, + rootGetters, +}) => ({ branch, commit_message: state.commitMessage || getters.preBuiltCommitMessage, actions: getCommitFiles(rootState.stagedFiles).map(f => ({ @@ -146,7 +153,7 @@ export const createCommitPayload = ({ branch, getters, newBranch, state, rootSta encoding: f.base64 ? 'base64' : 'text', last_commit_id: newBranch || f.deleted || f.prevPath ? undefined : f.lastCommitSha, })), - start_branch: newBranch ? rootState.currentBranchId : undefined, + start_sha: newBranch ? rootGetters.lastCommit.short_id : undefined, }); export const createNewMergeRequestUrl = (projectUrl, source, target) => |