Browse Source

Adds fetch command to remotes

main
Eric Amodio 6 years ago
parent
commit
6857f7c6b5
7 changed files with 61 additions and 24 deletions
  1. +10
    -0
      package.json
  2. +15
    -1
      src/git/git.ts
  3. +8
    -2
      src/git/gitService.ts
  4. +11
    -9
      src/git/models/repository.ts
  5. +6
    -1
      src/views/nodes/remoteNode.ts
  6. +6
    -6
      src/views/nodes/repositoryNode.ts
  7. +5
    -5
      src/views/viewCommands.ts

+ 10
- 0
package.json View File

@ -3552,6 +3552,11 @@
"group": "8_gitlens@2" "group": "8_gitlens@2"
}, },
{ {
"command": "gitlens.views.fetch",
"when": "viewItem == gitlens:remote",
"group": "inline@97"
},
{
"command": "gitlens.openRepoInRemote", "command": "gitlens.openRepoInRemote",
"when": "viewItem == gitlens:remote", "when": "viewItem == gitlens:remote",
"group": "inline@98" "group": "inline@98"
@ -3567,6 +3572,11 @@
"group": "1_gitlens@2" "group": "1_gitlens@2"
}, },
{ {
"command": "gitlens.views.fetch",
"when": "viewItem == gitlens:remote",
"group": "2_gitlens@1"
},
{
"command": "gitlens.views.terminalRemoveRemote", "command": "gitlens.views.terminalRemoveRemote",
"when": "viewItem == gitlens:remote", "when": "viewItem == gitlens:remote",
"group": "8_gitlens@1" "group": "8_gitlens@1"

+ 15
- 1
src/git/git.ts View File

@ -66,7 +66,9 @@ const GitWarnings = {
noUpstream: /no upstream configured for branch \'(.*?)\'/i, noUpstream: /no upstream configured for branch \'(.*?)\'/i,
unknownRevision: /ambiguous argument \'.*?\': unknown revision or path not in the working tree|not stored as a remote-tracking branch/i, unknownRevision: /ambiguous argument \'.*?\': unknown revision or path not in the working tree|not stored as a remote-tracking branch/i,
mustRunInWorkTree: /this operation must be run in a work tree/i, mustRunInWorkTree: /this operation must be run in a work tree/i,
patchWithConflicts: /Applied patch to \'.*?\' with conflicts/i
patchWithConflicts: /Applied patch to \'.*?\' with conflicts/i,
noRemoteRepositorySpecified: /No remote repository specified\./i,
remoteConnectionError: /Could not read from remote repository/i
}; };
interface GitCommandOptions extends RunOptions { interface GitCommandOptions extends RunOptions {
@ -464,6 +466,18 @@ export class Git {
return git<string>({ cwd: repoPath }, ...params); return git<string>({ cwd: repoPath }, ...params);
} }
static fetch(repoPath: string, options: { all?: boolean; remote?: string } = {}) {
const params = ['fetch'];
if (options.remote) {
params.push(options.remote);
}
else if (options.all) {
params.push('--all');
}
return git<string>({ cwd: repoPath }, ...params);
}
static log(repoPath: string, options: { author?: string; maxCount?: number; ref?: string; reverse?: boolean }) { static log(repoPath: string, options: { author?: string; maxCount?: number; ref?: string; reverse?: boolean }) {
const params = ['-c', 'diff.renameLimit=0', ...defaultLogParams, '--full-history', '-M', '-m']; const params = ['-c', 'diff.renameLimit=0', ...defaultLogParams, '--full-history', '-M', '-m'];
if (options.author) { if (options.author) {

+ 8
- 2
src/git/gitService.ts View File

@ -466,6 +466,12 @@ export class GitService implements Disposable {
@gate() @gate()
@log() @log()
async fetch(repoPath: string, remote?: string) {
return Git.fetch(repoPath, { remote: remote });
}
@gate()
@log()
async fetchAll() { async fetchAll() {
const repositories = [...(await this.getRepositories())]; const repositories = [...(await this.getRepositories())];
if (repositories.length === 0) return; if (repositories.length === 0) return;
@ -486,7 +492,7 @@ export class GitService implements Disposable {
increment: (i / total) * 100 increment: (i / total) * 100
}); });
await repo.fetch(false);
await this.fetch(repo.path);
} }
} }
); );
@ -514,7 +520,7 @@ export class GitService implements Disposable {
increment: (i / total) * 100 increment: (i / total) * 100
}); });
await repo.pull(false);
await repo.pull({ progress: false });
} }
} }
); );

+ 11
- 9
src/git/models/repository.ts View File

@ -225,22 +225,22 @@ export class Repository implements Disposable {
@gate() @gate()
@log() @log()
async fetch(progress: boolean = true) {
if (!progress) return this.fetchCore();
async fetch(options: { progress?: boolean; remote?: string } = {}) {
const { progress, ...opts } = { progress: true, ...options };
if (!progress) return this.fetchCore(opts);
await window.withProgress( await window.withProgress(
{ {
location: ProgressLocation.Notification, location: ProgressLocation.Notification,
title: `Fetching ${this.formattedName}...`,
title: `Fetching ${opts.remote ? `${opts.remote} of ` : ''}${this.formattedName}...`,
cancellable: false cancellable: false
}, },
() => this.fetchCore()
() => this.fetchCore(opts)
); );
} }
private async fetchCore() {
await commands.executeCommand('git.fetch', this.path);
private async fetchCore(options: { remote?: string } = {}) {
await Container.git.fetch(this.path, options.remote);
this.fireChange(RepositoryChange.Repository); this.fireChange(RepositoryChange.Repository);
} }
@ -308,7 +308,8 @@ export class Repository implements Disposable {
@gate() @gate()
@log() @log()
async pull(progress: boolean = true) {
async pull(options: { progress?: boolean } = {}) {
const { progress } = { progress: true, ...options };
if (!progress) return this.pullCore(); if (!progress) return this.pullCore();
await window.withProgress( await window.withProgress(
@ -329,7 +330,8 @@ export class Repository implements Disposable {
@gate() @gate()
@log() @log()
async push(force: boolean = false, progress: boolean = true) {
async push(options: { force?: boolean; progress?: boolean } = {}) {
const { force, progress } = { progress: true, ...options };
if (!progress) return this.pushCore(force); if (!progress) return this.pushCore(force);
await window.withProgress( await window.withProgress(

+ 6
- 1
src/views/nodes/remoteNode.ts View File

@ -4,7 +4,7 @@ import { ViewBranchesLayout } from '../../configuration';
import { GlyphChars } from '../../constants'; import { GlyphChars } from '../../constants';
import { Container } from '../../container'; import { Container } from '../../container';
import { GitRemote, GitRemoteType, GitUri, Repository } from '../../git/gitService'; import { GitRemote, GitRemoteType, GitUri, Repository } from '../../git/gitService';
import { Arrays, Iterables } from '../../system';
import { Arrays, Iterables, log } from '../../system';
import { RepositoriesView } from '../repositoriesView'; import { RepositoriesView } from '../repositoriesView';
import { BranchNode } from './branchNode'; import { BranchNode } from './branchNode';
import { BranchOrTagFolderNode } from './branchOrTagFolderNode'; import { BranchOrTagFolderNode } from './branchOrTagFolderNode';
@ -107,4 +107,9 @@ ${this.remote.path} (${this.remote.provider !== undefined ? this.remote.provider
return item; return item;
} }
@log()
fetch(options: { progress?: boolean } = {}) {
return this.repo.fetch({ ...options, remote: this.remote.name });
}
} }

+ 6
- 6
src/views/nodes/repositoryNode.ts View File

@ -167,18 +167,18 @@ export class RepositoryNode extends SubscribeableViewNode {
} }
@log() @log()
fetch(progress: boolean = true) {
return this.repo.fetch(progress);
fetch(options: { progress?: boolean; remote?: string } = {}) {
return this.repo.fetch(options);
} }
@log() @log()
pull(progress: boolean = true) {
return this.repo.pull(progress);
pull(options: { progress?: boolean } = {}) {
return this.repo.pull(options);
} }
@log() @log()
push(force: boolean = false, progress: boolean = true) {
return this.repo.push(force, progress);
push(options: { force?: boolean; progress?: boolean } = {}) {
return this.repo.push(options);
} }
@gate() @gate()

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

@ -108,10 +108,10 @@ export class ViewCommands implements Disposable {
this._disposable && this._disposable.dispose(); this._disposable && this._disposable.dispose();
} }
private fetch(node: RepositoryNode) {
if (!(node instanceof RepositoryNode)) return;
return node.fetch();
private fetch(node: RemoteNode | RepositoryNode) {
if (node instanceof RemoteNode) return node.fetch();
if (node instanceof RepositoryNode) return node.fetch();
return;
} }
private pull(node: RepositoryNode | StatusUpstreamNode) { private pull(node: RepositoryNode | StatusUpstreamNode) {
@ -129,7 +129,7 @@ export class ViewCommands implements Disposable {
} }
if (!(node instanceof RepositoryNode)) return; if (!(node instanceof RepositoryNode)) return;
return node.push(force);
return node.push({ force: force });
} }
private async applyChanges(node: CommitFileNode | StashFileNode | ResultsFileNode) { private async applyChanges(node: CommitFileNode | StashFileNode | ResultsFileNode) {

Loading…
Cancel
Save