Git - add fetch, pull, push commands to incoming/outgoing (#202809)

This commit is contained in:
Ladislau Szomoru 2024-01-19 11:25:59 +01:00 committed by GitHub
parent 3b9f4a340c
commit 0287cb9fe7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 110 additions and 28 deletions

View file

@ -10,25 +10,26 @@
},
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
"enabledApiProposals": [
"diffCommand",
"contribEditorContentMenu",
"contribEditSessions",
"canonicalUriProvider",
"contribViewsWelcome",
"editSessionIdentityProvider",
"quickDiffProvider",
"scmActionButton",
"scmHistoryProvider",
"scmSelectedProvider",
"scmValidation",
"scmMultiDiffEditor",
"tabInputTextMerge",
"timeline",
"contribEditSessions",
"contribEditorContentMenu",
"contribMergeEditorMenus",
"contribMultiDiffEditorMenus",
"contribSourceControlHistoryItemGroupMenu",
"contribSourceControlHistoryItemMenu",
"contribSourceControlInputBoxMenu",
"contribViewsWelcome",
"diffCommand",
"editSessionIdentityProvider",
"quickDiffProvider",
"quickPickSortByLabel",
"contribSourceControlHistoryItemMenu"
"scmActionButton",
"scmHistoryProvider",
"scmMultiDiffEditor",
"scmSelectedProvider",
"scmValidation",
"tabInputTextMerge",
"timeline"
],
"categories": [
"Other"
@ -511,6 +512,13 @@
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.fetchRef",
"title": "%command.fetch%",
"icon": "$(git-fetch)",
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.pull",
"title": "%command.pull%",
@ -529,6 +537,13 @@
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.pullRef",
"title": "%command.pull%",
"icon": "$(repo-pull)",
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.push",
"title": "%command.push%",
@ -571,6 +586,13 @@
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.pushRef",
"title": "%command.push%",
"icon": "$(repo-push)",
"category": "Git",
"enablement": "!operationInProgress"
},
{
"command": "git.cherryPick",
"title": "%command.cherryPick%",
@ -1335,6 +1357,18 @@
{
"command": "git.unstageFile",
"when": "false"
},
{
"command": "git.fetchRef",
"when": "false"
},
{
"command": "git.pullRef",
"when": "false"
},
{
"command": "git.pushRef",
"when": "false"
}
],
"scm/title": [
@ -1802,6 +1836,18 @@
"group": "1_modification@3"
}
],
"scm/incomingChanges": [
{
"command": "git.fetchRef",
"group": "navigation",
"when": "scmProvider == git"
},
{
"command": "git.pullRef",
"group": "navigation",
"when": "scmProvider == git"
}
],
"scm/incomingChanges/allChanges/context": [
{
"command": "git.viewAllChanges",
@ -1816,6 +1862,13 @@
"group": "inline@1"
}
],
"scm/outgoingChanges": [
{
"command": "git.pushRef",
"group": "navigation",
"when": "scmProvider == git"
}
],
"scm/outgoingChanges/allChanges/context": [
{
"command": "git.viewAllChanges",

View file

@ -2961,6 +2961,16 @@ export class CommandCenter {
await repository.fetchAll();
}
@command('git.fetchRef', { repository: true })
async fetchRef(repository: Repository, ref: string): Promise<void> {
if (!repository || !ref) {
return;
}
const branch = await repository.getBranch(ref);
await repository.fetch({ remote: branch.remote, ref: branch.name });
}
@command('git.pullFrom', { repository: true })
async pullFrom(repository: Repository): Promise<void> {
const remotes = repository.remotes;
@ -3023,6 +3033,16 @@ export class CommandCenter {
await repository.pullWithRebase(repository.HEAD);
}
@command('git.pullRef', { repository: true })
async pullRef(repository: Repository, ref: string): Promise<void> {
if (!repository || !ref) {
return;
}
const branch = await repository.getBranch(ref);
await repository.pullFrom(false, branch.remote, branch.name);
}
private async _push(repository: Repository, pushOptions: PushOptions) {
const remotes = repository.remotes;
@ -3160,6 +3180,15 @@ export class CommandCenter {
await this._push(repository, { pushType: PushType.PushFollowTags, forcePush: true });
}
@command('git.pushRef', { repository: true })
async pushRef(repository: Repository, ref: string): Promise<void> {
if (!repository || !ref) {
return;
}
await this._push(repository, { pushType: PushType.Push });
}
@command('git.cherryPick', { repository: true })
async cherryPick(repository: Repository): Promise<void> {
const hash = await window.showInputBox({

View file

@ -191,21 +191,21 @@ export class GitHistoryProvider implements SourceControlHistoryProvider, FileDec
return HEAD.upstream;
}
try {
const remoteBranch = await this.repository.getBranchBase(HEAD.name ?? '');
if (!remoteBranch?.remote || !remoteBranch?.name || !remoteBranch?.commit || remoteBranch?.type !== RefType.RemoteHead) {
return undefined;
}
// try {
// const remoteBranch = await this.repository.getBranchBase(HEAD.name ?? '');
// if (!remoteBranch?.remote || !remoteBranch?.name || !remoteBranch?.commit || remoteBranch?.type !== RefType.RemoteHead) {
// return undefined;
// }
return {
name: remoteBranch.name,
remote: remoteBranch.remote,
commit: remoteBranch.commit
};
}
catch (err) {
this.logger.error(`Failed to get branch base for '${HEAD.name}': ${err.message}`);
}
// return {
// name: remoteBranch.name,
// remote: remoteBranch.remote,
// commit: remoteBranch.commit
// };
// }
// catch (err) {
// this.logger.error(`Failed to get branch base for '${HEAD.name}': ${err.message}`);
// }
return undefined;
}