Browse Source

Adds constants for built-in git config/commands

main
Eric Amodio 3 years ago
parent
commit
4a6d438c44
4 changed files with 31 additions and 9 deletions
  1. +2
    -2
      src/commands/git/push.ts
  2. +13
    -0
      src/constants.ts
  3. +14
    -5
      src/git/models/repository.ts
  4. +2
    -2
      src/views/viewCommands.ts

+ 2
- 2
src/commands/git/push.ts View File

@ -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<Flags[]> {
const useForceWithLease = configuration.getAny<boolean>('git.useForcePushWithLease') ?? false;
const useForceWithLease = configuration.getAny<boolean>(BuiltInGitConfiguration.UseForcePushWithLease) ?? false;
let step: QuickPickStep<FlagsQuickPickItem<Flags>>;

+ 13
- 0
src/constants.ts View File

@ -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',

+ 14
- 5
src/git/models/repository.ts View File

@ -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<boolean>('git.fetchOnPull', Uri.file(this.path))) {
void (await commands.executeCommand(
options.rebase ? BuiltInGitCommands.PullRebase : BuiltInGitCommands.Pull,
this.path,
));
} else if (configuration.getAny<boolean>(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);

+ 2
- 2
src/views/viewCommands.ts View File

@ -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()

Loading…
Cancel
Save