Commit 0531631c authored by Phil Hughes's avatar Phil Hughes

disable current branch option in commit form is user does not have permissions to push

parent 9b760c4c
...@@ -10,7 +10,7 @@ export default { ...@@ -10,7 +10,7 @@ export default {
}, },
computed: { computed: {
...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']), ...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
...mapGetters(['currentProject']), ...mapGetters(['currentProject', 'currentBranch']),
commitToCurrentBranchText() { commitToCurrentBranchText() {
return sprintf( return sprintf(
__('Commit to %{branchName} branch'), __('Commit to %{branchName} branch'),
...@@ -23,7 +23,9 @@ export default { ...@@ -23,7 +23,9 @@ export default {
}, },
}, },
mounted() { mounted() {
if (this.disableMergeRequestRadio) { if (!this.currentBranch.can_push) {
this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH);
} else if (this.disableMergeRequestRadio) {
this.updateCommitAction(consts.COMMIT_TO_CURRENT_BRANCH); this.updateCommitAction(consts.COMMIT_TO_CURRENT_BRANCH);
} }
}, },
...@@ -33,6 +35,9 @@ export default { ...@@ -33,6 +35,9 @@ export default {
commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH, commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH,
commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH, commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH,
commitToNewBranchMR: consts.COMMIT_TO_NEW_BRANCH_MR, commitToNewBranchMR: consts.COMMIT_TO_NEW_BRANCH_MR,
currentBranchPermissionsTooltip: __(
"This option is disabled as you don't have write permissions for the current branch",
),
}; };
</script> </script>
...@@ -40,10 +45,12 @@ export default { ...@@ -40,10 +45,12 @@ export default {
<div class="append-bottom-15 ide-commit-radios"> <div class="append-bottom-15 ide-commit-radios">
<radio-group <radio-group
:value="$options.commitToCurrentBranch" :value="$options.commitToCurrentBranch"
:checked="true" :disabled="!currentBranch.can_push"
:title="$options.currentBranchPermissionsTooltip"
> >
<span <span
v-html="commitToCurrentBranchText" v-html="commitToCurrentBranchText"
class="ide-radio-label"
> >
</span> </span>
</radio-group> </radio-group>
...@@ -56,6 +63,7 @@ export default { ...@@ -56,6 +63,7 @@ export default {
v-if="currentProject.merge_requests_enabled" v-if="currentProject.merge_requests_enabled"
:value="$options.commitToNewBranchMR" :value="$options.commitToNewBranchMR"
:label="__('Create a new branch and merge request')" :label="__('Create a new branch and merge request')"
:title="__('This option is disabled while you still have unstaged changes')"
:show-input="true" :show-input="true"
:disabled="disableMergeRequestRadio" :disabled="disableMergeRequestRadio"
/> />
......
<script> <script>
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { __ } from '~/locale';
import tooltip from '~/vue_shared/directives/tooltip'; import tooltip from '~/vue_shared/directives/tooltip';
export default { export default {
...@@ -32,14 +31,17 @@ export default { ...@@ -32,14 +31,17 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
title: {
type: String,
required: false,
default: '',
},
}, },
computed: { computed: {
...mapState('commit', ['commitAction']), ...mapState('commit', ['commitAction']),
...mapGetters('commit', ['newBranchName']), ...mapGetters('commit', ['newBranchName']),
tooltipTitle() { tooltipTitle() {
return this.disabled return this.disabled ? this.title : '';
? __('This option is disabled while you still have unstaged changes')
: '';
}, },
}, },
methods: { methods: {
......
...@@ -82,10 +82,13 @@ export const getStagedFilesCountForPath = state => path => ...@@ -82,10 +82,13 @@ export const getStagedFilesCountForPath = state => path =>
getChangesCountForFiles(state.stagedFiles, path); getChangesCountForFiles(state.stagedFiles, path);
export const lastCommit = (state, getters) => { export const lastCommit = (state, getters) => {
const branch = getters.currentProject && getters.currentProject.branches[state.currentBranchId]; const branch = getters.currentProject && getters.currentBranch;
return branch ? branch.commit : null; return branch ? branch.commit : null;
}; };
export const currentBranch = (state, getters) =>
getters.currentProject.branches[state.currentBranchId];
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
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