diff --git a/extensions/git/package.json b/extensions/git/package.json index 0a9c6904555..e909d5f5030 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -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", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 81abbd94aa0..6a15bd94455 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -2961,6 +2961,16 @@ export class CommandCenter { await repository.fetchAll(); } + @command('git.fetchRef', { repository: true }) + async fetchRef(repository: Repository, ref: string): Promise { + 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 { 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 { + 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 { + if (!repository || !ref) { + return; + } + + await this._push(repository, { pushType: PushType.Push }); + } + @command('git.cherryPick', { repository: true }) async cherryPick(repository: Repository): Promise { const hash = await window.showInputBox({ diff --git a/extensions/git/src/historyProvider.ts b/extensions/git/src/historyProvider.ts index 9560aef5e8e..5d395c502c1 100644 --- a/extensions/git/src/historyProvider.ts +++ b/extensions/git/src/historyProvider.ts @@ -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; }