Skip to content

Commit cf33c45

Browse files
authored
Feat: Add context menu command to reset current branch to tag (#3769)
* add & register command * accept git tag reference in git reset * Update CHANGELOG * reorder lines in package.json + add !listMultiSelection cond
1 parent 1665ce9 commit cf33c45

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1414

1515
## [16.0.1] - 2024-11-15
1616

17+
### Added
18+
19+
- Adds context menu command in _Commit Graph_ to reset Current Branch to a tag.
20+
1721
### Changed
1822

1923
- Changes the _Search & Compare_ view to be separate (detached) from the new grouped _GitLens_ view

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9014,6 +9014,13 @@
90149014
"title": "Reset Current Branch to Commit...",
90159015
"enablement": "!operationInProgress"
90169016
},
9017+
{
9018+
"command": "gitlens.graph.resetToTag",
9019+
"title": "Reset Current Branch to Tag...",
9020+
"category": "GitLens",
9021+
"icon": "$(gitlens-reset)",
9022+
"enablement": "!operationInProgress"
9023+
},
90179024
{
90189025
"command": "gitlens.graph.resetToTip",
90199026
"title": "Reset Current Branch to Tip...",
@@ -12432,6 +12439,10 @@
1243212439
"command": "gitlens.graph.switchToTag",
1243312440
"when": "false"
1243412441
},
12442+
{
12443+
"command": "gitlens.graph.resetToTag",
12444+
"when": "false"
12445+
},
1243512446
{
1243612447
"command": "gitlens.graph.createWorktree",
1243712448
"when": "false"
@@ -16292,6 +16303,11 @@
1629216303
"when": "!listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:commit\\b/",
1629316304
"group": "1_gitlens_actions@4"
1629416305
},
16306+
{
16307+
"command": "gitlens.graph.resetToTag",
16308+
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && !listMultiSelection && webviewItem =~ /gitlens:tag\\b/",
16309+
"group": "1_gitlens_actions@2"
16310+
},
1629516311
{
1629616312
"command": "gitlens.graph.resetToTip",
1629716313
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:branch\\b/",
@@ -16415,12 +16431,12 @@
1641516431
{
1641616432
"command": "gitlens.graph.deleteTag",
1641716433
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem == gitlens:tag",
16418-
"group": "1_gitlens_actions@2"
16434+
"group": "1_gitlens_actions@3"
1641916435
},
1642016436
{
1642116437
"command": "gitlens.graph.createBranch",
1642216438
"when": "!gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders && webviewItem =~ /gitlens:tag\\b/",
16423-
"group": "1_gitlens_actions@3"
16439+
"group": "1_gitlens_actions@4"
1642416440
},
1642516441
{
1642616442
"command": "gitlens.graph.hideTag",

src/commands/git/reset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Container } from '../../container';
22
import type { GitBranch } from '../../git/models/branch';
33
import type { GitLog } from '../../git/models/log';
4-
import type { GitReference, GitRevisionReference } from '../../git/models/reference';
4+
import type { GitReference, GitRevisionReference, GitTagReference } from '../../git/models/reference';
55
import { getReferenceLabel } from '../../git/models/reference';
66
import type { Repository } from '../../git/models/repository';
77
import type { FlagsQuickPickItem } from '../../quickpicks/items/flags';
@@ -31,7 +31,7 @@ type Flags = '--hard' | '--soft';
3131

3232
interface State {
3333
repo: string | Repository;
34-
reference: GitRevisionReference;
34+
reference: GitRevisionReference | GitTagReference;
3535
flags: Flags[];
3636
}
3737

src/git/actions/repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ResetGitCommandArgs } from '../../commands/git/reset';
22
import { Container } from '../../container';
33
import type { ViewsWithRepositoryFolders } from '../../views/viewBase';
44
import { executeGitCommand } from '../actions';
5-
import type { GitBranchReference, GitReference, GitRevisionReference } from '../models/reference';
5+
import type { GitBranchReference, GitReference, GitRevisionReference, GitTagReference } from '../models/reference';
66
import type { Repository } from '../models/repository';
77

88
export function cherryPick(repo?: string | Repository, refs?: GitRevisionReference | GitRevisionReference[]) {
@@ -40,7 +40,7 @@ export function rebase(repo?: string | Repository, ref?: GitReference, interacti
4040

4141
export function reset(
4242
repo?: string | Repository,
43-
ref?: GitRevisionReference,
43+
ref?: GitRevisionReference | GitTagReference,
4444
flags?: NonNullable<ResetGitCommandArgs['state']>['flags'],
4545
) {
4646
return executeGitCommand({

src/plus/webviews/graph/graphWebview.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
554554
this.host.registerWebviewCommand('gitlens.graph.createTag', this.createTag),
555555
this.host.registerWebviewCommand('gitlens.graph.deleteTag', this.deleteTag),
556556
this.host.registerWebviewCommand('gitlens.graph.switchToTag', this.switchTo),
557+
this.host.registerWebviewCommand('gitlens.graph.resetToTag', this.resetToTag),
557558

558559
this.host.registerWebviewCommand('gitlens.graph.createWorktree', this.createWorktree),
559560

@@ -3339,6 +3340,13 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
33393340
return RepoActions.switchTo(ref.repoPath, ref);
33403341
}
33413342

3343+
@log()
3344+
private resetToTag(item?: GraphItemContext) {
3345+
const ref = this.getGraphItemRef(item, 'tag');
3346+
if (ref == null) return Promise.resolve();
3347+
return RepoActions.reset(ref.repoPath, ref);
3348+
}
3349+
33423350
@log()
33433351
private hideRef(item?: GraphItemContext, options?: { group?: boolean; remote?: boolean }) {
33443352
let refs;

0 commit comments

Comments
 (0)