From 4a6d438c4451d38a477c9e38899eaec5893f553e Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 28 Feb 2021 01:01:50 -0500 Subject: [PATCH] Adds constants for built-in git config/commands --- src/commands/git/push.ts | 4 ++-- src/constants.ts | 13 +++++++++++++ src/git/models/repository.ts | 19 ++++++++++++++----- src/views/viewCommands.ts | 4 ++-- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/commands/git/push.ts b/src/commands/git/push.ts index 2e7f99f..c51e0b2 100644 --- a/src/commands/git/push.ts +++ b/src/commands/git/push.ts @@ -1,6 +1,6 @@ 'use strict'; import { configuration } from '../../configuration'; -import { GlyphChars } from '../../constants'; +import { BuiltInGitConfiguration, GlyphChars } from '../../constants'; import { Container } from '../../container'; import { GitBranch, GitBranchReference, GitReference, Repository } from '../../git/git'; import { @@ -152,7 +152,7 @@ export class PushGitCommand extends QuickCommand { } private async *confirmStep(state: PushStepState, context: Context): AsyncStepResultGenerator { - const useForceWithLease = configuration.getAny('git.useForcePushWithLease') ?? false; + const useForceWithLease = configuration.getAny(BuiltInGitConfiguration.UseForcePushWithLease) ?? false; let step: QuickPickStep>; diff --git a/src/constants.ts b/src/constants.ts index e9a22a3..c4d69e3 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -27,6 +27,19 @@ export enum BuiltInCommands { ShowReferences = 'editor.action.showReferences', } +export enum BuiltInGitCommands { + Pull = 'git.pull', + PullRebase = 'git.pullRebase', + Push = 'git.push', + PushForce = 'git.pushForce', + UndoCommit = 'git.undoCommit', +} + +export enum BuiltInGitConfiguration { + FetchOnPull = 'git.fetchOnPull', + UseForcePushWithLease = 'git.useForcePushWithLease', +} + export enum ContextKeys { ActionPrefix = 'gitlens:action:', ActiveFileStatus = 'gitlens:activeFileStatus', diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index d25eddc..d4a61d6 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -16,7 +16,7 @@ import { import { CreatePullRequestActionContext } from '../../api/gitlens'; import { executeActionCommand } from '../../commands'; import { BranchSorting, configuration, TagSorting } from '../../configuration'; -import { Starred, WorkspaceState } from '../../constants'; +import { BuiltInGitCommands, BuiltInGitConfiguration, Starred, WorkspaceState } from '../../constants'; import { Container } from '../../container'; import { GitBranch, @@ -690,8 +690,11 @@ export class Repository implements Disposable { try { const tracking = await this.hasTrackingBranch(); if (tracking) { - void (await commands.executeCommand(options.rebase ? 'git.pullRebase' : 'git.pull', this.path)); - } else if (configuration.getAny('git.fetchOnPull', Uri.file(this.path))) { + void (await commands.executeCommand( + options.rebase ? BuiltInGitCommands.PullRebase : BuiltInGitCommands.Pull, + this.path, + )); + } else if (configuration.getAny(BuiltInGitConfiguration.FetchOnPull, Uri.file(this.path))) { void (await Container.git.fetch(this.path)); } @@ -782,7 +785,10 @@ export class Repository implements Disposable { const currentBranch = await this.getBranch(); if (branch.id === currentBranch?.id) { - void (await commands.executeCommand(options.force ? 'git.pushForce' : 'git.push', this.path)); + void (await commands.executeCommand( + options.force ? BuiltInGitCommands.PushForce : BuiltInGitCommands.Push, + this.path, + )); } else { await repo?.push(branch.getRemoteName(), branch.name); } @@ -796,7 +802,10 @@ export class Repository implements Disposable { await repo?.push(branch.getRemoteName(), `${options.reference.ref}:${branch.getNameWithoutRemote()}`); } else { - void (await commands.executeCommand(options.force ? 'git.pushForce' : 'git.push', this.path)); + void (await commands.executeCommand( + options.force ? BuiltInGitCommands.PushForce : BuiltInGitCommands.Push, + this.path, + )); } this.fireChange(RepositoryChange.Unknown); diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index e64f8a6..14cccc3 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -13,7 +13,7 @@ import { OpenFileAtRevisionCommandArgs, } from '../commands'; import { configuration, FileAnnotationType, ViewShowBranchComparison } from '../configuration'; -import { BuiltInCommands, ContextKeys, setContext } from '../constants'; +import { BuiltInCommands, BuiltInGitCommands, ContextKeys, setContext } from '../constants'; import { Container } from '../container'; import { GitReference, GitRevision } from '../git/git'; import { GitUri } from '../git/gitUri'; @@ -635,7 +635,7 @@ export class ViewCommands { return; } - await commands.executeCommand('git.undoCommit', node.repoPath); + await commands.executeCommand(BuiltInGitCommands.UndoCommit, node.repoPath); } @debug()