( branchesState: IBranchesState, aheadBehind: IAheadBehind | null )
| 37 | * branch should be a force push |
| 38 | */ |
| 39 | export function getCurrentBranchForcePushState( |
| 40 | branchesState: IBranchesState, |
| 41 | aheadBehind: IAheadBehind | null |
| 42 | ): ForcePushBranchState { |
| 43 | if (aheadBehind === null) { |
| 44 | // no tracking branch found |
| 45 | return ForcePushBranchState.NotAvailable |
| 46 | } |
| 47 | |
| 48 | const { ahead, behind } = aheadBehind |
| 49 | |
| 50 | if (behind === 0 || ahead === 0) { |
| 51 | // no a diverged branch to force push |
| 52 | return ForcePushBranchState.NotAvailable |
| 53 | } |
| 54 | |
| 55 | const { tip, forcePushBranches } = branchesState |
| 56 | |
| 57 | let canForcePushBranch = false |
| 58 | if (tip.kind === TipState.Valid) { |
| 59 | const localBranchName = tip.branch.nameWithoutRemote |
| 60 | const { sha } = tip.branch.tip |
| 61 | const foundEntry = forcePushBranches.get(localBranchName) |
| 62 | canForcePushBranch = foundEntry === sha |
| 63 | } |
| 64 | |
| 65 | return canForcePushBranch |
| 66 | ? ForcePushBranchState.Recommended |
| 67 | : ForcePushBranchState.Available |
| 68 | } |
no test coverage detected