Browse Source

Fixes #399 - "Open x in Remote" commands aren't always available

Closes #209 - Open File in Remote should ask for a branch if no upstream
main
Eric Amodio 6 years ago
parent
commit
d2a7a1ceb3
10 changed files with 63 additions and 33 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +9
    -9
      package.json
  3. +11
    -8
      src/commands/openBranchInRemote.ts
  4. +18
    -2
      src/commands/openFileInRemote.ts
  5. +1
    -1
      src/constants.ts
  6. +9
    -0
      src/git/git.ts
  7. +5
    -5
      src/git/models/repository.ts
  8. +4
    -4
      src/gitService.ts
  9. +1
    -1
      src/trackers/documentTracker.ts
  10. +3
    -3
      src/trackers/trackedDocument.ts

+ 2
- 0
CHANGELOG.md View File

@ -7,9 +7,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## [Unreleased]
### Added
- Adds clipboard support for Linux without requiring any external dependencies — thanks to [PR #394](https://github.com/eamodio/vscode-gitlens/pull/394) by Cédric Malard ([@cmalard](https://github.com/cmalard))
- Adds a select branch quick pick menu to the *Open File in Remote* command (`gitlens.openFileInRemote`) when the current branch has no upstream tracking branch — closes [#209](https://github.com/eamodio/vscode-gitlens/issues/209)
### Fixed
- Fixes [#400](https://github.com/eamodio/vscode-gitlens/issues/400) - Reset TO commit also resets chosen one
- Fixes [#399](https://github.com/eamodio/vscode-gitlens/issues/399) - "Open x in Remote" commands aren't always available
- Fixes [#397](https://github.com/eamodio/vscode-gitlens/issues/397) - Error while opening the gitlens view using `Open View` command
- Fixes [#391](https://github.com/eamodio/vscode-gitlens/issues/391) - GitLens adds some settings in settings.json
- Fixes another case of [#343](https://github.com/eamodio/vscode-gitlens/issues/343) - Can't show blame when VSCode starts on branch without upstream — thanks to [PR #390](https://github.com/eamodio/vscode-gitlens/pull/390) by ryenus ([@ryenus](https://github.com/ryenus))

+ 9
- 9
package.json View File

@ -2068,19 +2068,19 @@
},
{
"command": "gitlens.openBranchesInRemote",
"when": "gitlens:activeHasRemote"
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.openBranchInRemote",
"when": "gitlens:activeHasRemote"
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.openCommitInRemote",
"when": "gitlens:activeIsBlameable && gitlens:activeHasRemote"
"when": "gitlens:activeIsBlameable && gitlens:activeHasRemotes"
},
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:activeIsTracked && gitlens:activeHasRemote"
"when": "gitlens:activeIsTracked && gitlens:activeHasRemotes"
},
{
"command": "gitlens.openFileRevision",
@ -2088,7 +2088,7 @@
},
{
"command": "gitlens.openRepoInRemote",
"when": "gitlens:activeHasRemote"
"when": "gitlens:hasRemotes"
},
{
"command": "gitlens.openWorkingFile",
@ -2372,12 +2372,12 @@
},
{
"command": "gitlens.openFileInRemote",
"when": "editorTextFocus && gitlens:activeHasRemote && config.gitlens.menus.editor.remote",
"when": "editorTextFocus && gitlens:activeHasRemotes && config.gitlens.menus.editor.remote",
"group": "1_gitlens_1@1"
},
{
"command": "gitlens.openCommitInRemote",
"when": "editorTextFocus && gitlens:activeHasRemote && config.gitlens.menus.editor.remote",
"when": "editorTextFocus && gitlens:activeHasRemotes && config.gitlens.menus.editor.remote",
"group": "1_gitlens_1@2"
},
{
@ -2450,7 +2450,7 @@
},
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.menus.editorGroup.remote",
"when": "gitlens:enabled && gitlens:activeHasRemotes && config.gitlens.menus.editorGroup.remote",
"group": "4_gitlens"
},
{
@ -2462,7 +2462,7 @@
"editor/title/context": [
{
"command": "gitlens.openFileInRemote",
"when": "gitlens:enabled && gitlens:activeHasRemote && config.gitlens.menus.editorTab.remote",
"when": "gitlens:enabled && gitlens:activeHasRemotes && config.gitlens.menus.editorTab.remote",
"group": "2_files@100"
},
{

+ 11
- 8
src/commands/openBranchInRemote.ts View File

@ -41,15 +41,18 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
if (args.branch === undefined) {
args = { ...args };
const branches = await Container.git.getBranches(repoPath);
const branches = (await Container.git.getBranches(repoPath)).filter(b => b.tracking !== undefined);
if (branches.length > 1) {
const pick = await BranchesQuickPick.show(branches, `Open which branch in remote${GlyphChars.Ellipsis}`);
if (pick === undefined) return undefined;
const pick = await BranchesQuickPick.show(branches, `Open which branch in remote${GlyphChars.Ellipsis}`);
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return undefined;
if (pick instanceof CommandQuickPickItem) return undefined;
args.branch = pick.branch.name;
if (args.branch === undefined) return undefined;
args.branch = pick.branch.name;
}
else if (branches.length === 1) {
args.branch = branches[0].name;
}
}
const remotes = await Container.git.getRemotes(repoPath);
@ -57,7 +60,7 @@ export class OpenBranchInRemoteCommand extends ActiveEditorCommand {
return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: 'branch',
branch: args.branch
branch: args.branch || 'HEAD'
},
remote: args.remote,
remotes

+ 18
- 2
src/commands/openFileInRemote.ts View File

@ -1,10 +1,12 @@
'use strict';
import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithBranch, isCommandViewContextWithCommit } from './common';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitUri } from '../gitService';
import { Logger } from '../logger';
import { OpenInRemoteCommandArgs } from './openInRemote';
import { BranchesQuickPick, CommandQuickPickItem } from '../quickPicks/quickPicks';
export interface OpenFileInRemoteCommandArgs {
branch?: string;
@ -39,7 +41,21 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
if (args.branch === undefined) {
const branch = await Container.git.getBranch(gitUri.repoPath);
if (branch !== undefined) {
if (branch === undefined || branch.tracking === undefined) {
const branches = (await Container.git.getBranches(gitUri.repoPath)).filter(b => b.tracking !== undefined);
if (branches.length > 1) {
const pick = await BranchesQuickPick.show(branches, `Open ${gitUri.getRelativePath()} in remote for which branch${GlyphChars.Ellipsis}`);
if (pick === undefined) return undefined;
if (pick instanceof CommandQuickPickItem) return undefined;
args.branch = pick.branch.name;
}
else if (branches.length === 1) {
args.branch = branches[0].name;
}
}
else {
args.branch = branch.name;
}
}
@ -53,7 +69,7 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: gitUri.sha === undefined ? 'file' : 'revision',
branch: args.branch,
branch: args.branch || 'HEAD',
fileName: gitUri.getRelativePath(),
range: range,
sha: gitUri.sha

+ 1
- 1
src/constants.ts View File

@ -24,7 +24,7 @@ export enum BuiltInCommands {
}
export enum CommandContext {
ActiveHasRemote = 'gitlens:activeHasRemote',
ActiveHasRemotes = 'gitlens:activeHasRemotes',
ActiveIsBlameable = 'gitlens:activeIsBlameable',
ActiveFileIsTracked = 'gitlens:activeIsTracked',
ActiveIsRevision = 'gitlens:activeIsRevision',

+ 9
- 0
src/git/git.ts View File

@ -333,6 +333,15 @@ export class Git {
return gitCommand({ cwd: repoPath }, ...params);
}
static branch_contains(repoPath: string, ref: string, options: { remote: boolean } = { remote: false }) {
const params = ['branch', '--contains'];
if (options.remote) {
params.push('-r');
}
return gitCommand({ cwd: repoPath }, ...params, ref);
}
static checkout(repoPath: string, fileName: string, sha: string) {
const [file, root] = Git.splitPath(fileName, repoPath);

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

@ -249,16 +249,16 @@ export class Repository extends Disposable {
return Container.git.getTags(this.path);
}
async hasRemote(): Promise<boolean> {
const branch = await this.getBranch();
return branch !== undefined && branch.tracking !== undefined;
}
async hasRemotes(): Promise<boolean> {
const remotes = await this.getRemotes();
return remotes !== undefined && remotes.length > 0;
}
async hasTrackingBranch(): Promise<boolean> {
const branch = await this.getBranch();
return branch !== undefined && branch.tracking !== undefined;
}
resume() {
if (!this._suspended) return;

+ 4
- 4
src/gitService.ts View File

@ -1132,22 +1132,22 @@ export class GitService extends Disposable {
}
}
async hasRemote(repoPath: string | undefined): Promise<boolean> {
async hasRemotes(repoPath: string | undefined): Promise<boolean> {
if (repoPath === undefined) return false;
const repository = await this.getRepository(repoPath);
if (repository === undefined) return false;
return repository.hasRemote();
return repository.hasRemotes();
}
async hasRemotes(repoPath: string | undefined): Promise<boolean> {
async hasTrackingBranch(repoPath: string | undefined): Promise<boolean> {
if (repoPath === undefined) return false;
const repository = await this.getRepository(repoPath);
if (repository === undefined) return false;
return repository.hasRemotes();
return repository.hasTrackingBranch();
}
async getMergeBase(repoPath: string, ref1: string, ref2: string, options: { forkPoint?: boolean } = {}) {

+ 1
- 1
src/trackers/documentTracker.ts View File

@ -91,7 +91,7 @@ export class DocumentTracker extends Disposable {
setCommandContext(CommandContext.ActiveIsRevision, false);
setCommandContext(CommandContext.ActiveFileIsTracked, false);
setCommandContext(CommandContext.ActiveIsBlameable, false);
setCommandContext(CommandContext.ActiveHasRemote, false);
setCommandContext(CommandContext.ActiveHasRemotes, false);
return;
}

+ 3
- 3
src/trackers/trackedDocument.ts View File

@ -120,7 +120,7 @@ export class TrackedDocument extends Disposable {
setCommandContext(CommandContext.ActiveIsRevision, this.isRevision);
setCommandContext(CommandContext.ActiveFileIsTracked, this.isTracked);
setCommandContext(CommandContext.ActiveIsBlameable, this.isBlameable);
setCommandContext(CommandContext.ActiveHasRemote, this.hasRemotes);
setCommandContext(CommandContext.ActiveHasRemotes, this.hasRemotes);
}
async ensureInitialized() {
@ -189,7 +189,7 @@ export class TrackedDocument extends Disposable {
}
if (repo !== undefined) {
this._hasRemotes = await repo.hasRemote();
this._hasRemotes = await repo.hasRemotes();
}
else {
this._hasRemotes = false;
@ -201,7 +201,7 @@ export class TrackedDocument extends Disposable {
setCommandContext(CommandContext.ActiveIsRevision, this.isRevision);
setCommandContext(CommandContext.ActiveFileIsTracked, this.isTracked);
setCommandContext(CommandContext.ActiveIsBlameable, blameable);
setCommandContext(CommandContext.ActiveHasRemote, this.hasRemotes);
setCommandContext(CommandContext.ActiveHasRemotes, this.hasRemotes);
if (!options.initializing && wasBlameable !== blameable) {
const e = { editor: active, document: this, blameable: blameable } as DocumentBlameStateChangeEvent<T>;

Loading…
Cancel
Save