Skip to content

Commit

Permalink
Merge pull request #15309 from desktop/update-from-contribution-target
Browse files Browse the repository at this point in the history
Allow update from contribution target unless you're on it
  • Loading branch information
niik authored Sep 20, 2022
2 parents 4d44761 + 2fdc0fc commit 34d391b
Showing 1 changed file with 14 additions and 4 deletions.
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

1 comment on commit 34d391b

@braxtone83
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds so fat # What should you do?

Please sign in to comment.