Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow update from contribution target unless you're on it #15309

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/src/lib/menu-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TipState } from '../models/tip'
import { updateMenuState as ipcUpdateMenuState } from '../ui/main-process-proxy'
import { AppMenu, MenuItem } from '../models/app-menu'
import { hasConflictedFiles } from './status'
import { findContributionTargetDefaultBranch } from './branch'

export interface IMenuItemState {
readonly enabled?: boolean
Expand Down Expand Up @@ -159,13 +160,14 @@ function getRepositoryMenuBuilder(state: IAppState): MenuStateBuilder {
let onDetachedHead = false
let hasChangedFiles = false
let hasConflicts = false
let hasDefaultBranch = false
let hasPublishedBranch = false
let networkActionInProgress = false
let tipStateIsUnknown = false
let branchIsUnborn = false
let rebaseInProgress = false
let branchHasStashEntry = false
let onContributionTargetDefaultBranch = false
let hasContributionTargetDefaultBranch = false

// check that its a github repo and if so, that is has issues enabled
const repoIssuesEnabled =
Expand All @@ -180,12 +182,18 @@ function getRepositoryMenuBuilder(state: IAppState): MenuStateBuilder {
const tip = branchesState.tip
const defaultBranch = branchesState.defaultBranch

hasDefaultBranch = Boolean(defaultBranch)

onBranch = tip.kind === TipState.Valid
onDetachedHead = tip.kind === TipState.Detached
tipStateIsUnknown = tip.kind === TipState.Unknown
branchIsUnborn = tip.kind === TipState.Unborn
const contributionTarget = findContributionTargetDefaultBranch(
selectedState.repository,
branchesState
)
hasContributionTargetDefaultBranch = contributionTarget !== null
onContributionTargetDefaultBranch =
tip.kind === TipState.Valid &&
contributionTarget?.name === tip.branch.name

// If we are:
// 1. on the default branch, or
Expand Down Expand Up @@ -257,7 +265,9 @@ function getRepositoryMenuBuilder(state: IAppState): MenuStateBuilder {
)
menuStateBuilder.setEnabled(
'update-branch-with-contribution-target-branch',
onNonDefaultBranch && hasDefaultBranch && !onDetachedHead
onBranch &&
hasContributionTargetDefaultBranch &&
!onContributionTargetDefaultBranch
)
menuStateBuilder.setEnabled('merge-branch', onBranch)
menuStateBuilder.setEnabled('squash-and-merge-branch', onBranch)
Expand Down