Преглед на файлове

Changes unpublished commits icon to upload

Adds undo commit action to first unpublished commit
main
Eric Amodio преди 4 години
родител
ревизия
aa51162c42
променени са 11 файла, в които са добавени 94 реда и са изтрити 25 реда
  1. +20
    -0
      package.json
  2. +10
    -5
      src/commands/git/reset.ts
  3. +8
    -2
      src/commands/gitCommands.actions.ts
  4. +18
    -3
      src/views/nodes/branchNode.ts
  5. +4
    -1
      src/views/nodes/branchTrackingStatusNode.ts
  6. +2
    -2
      src/views/nodes/commitFileNode.ts
  7. +13
    -9
      src/views/nodes/commitNode.ts
  8. +1
    -1
      src/views/nodes/contributorNode.ts
  9. +1
    -1
      src/views/nodes/resultsCommitsNode.ts
  10. +1
    -1
      src/views/nodes/tagNode.ts
  11. +16
    -0
      src/views/viewCommands.ts

+ 20
- 0
package.json Целия файл

@ -3571,6 +3571,12 @@
"category": "GitLens"
},
{
"command": "gitlens.views.undoCommit",
"title": "Undo Commit",
"category": "GitLens",
"icon": "$(discard)"
},
{
"command": "gitlens.views.terminalRemoveRemote",
"title": "Remove Remote (via Terminal)",
"category": "GitLens"
@ -4931,6 +4937,10 @@
"when": "false"
},
{
"command": "gitlens.views.undoCommit",
"when": "false"
},
{
"command": "gitlens.views.terminalRemoveRemote",
"when": "false"
},
@ -6419,6 +6429,11 @@
"group": "inline@9"
},
{
"command": "gitlens.views.undoCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+HEAD\\b)(?=.*?\\b\\+unpublished\\b)/",
"group": "inline@96"
},
{
"command": "gitlens.views.compareWithHead",
"when": "viewItem =~ /gitlens:(branch\\b(?!.*?\\b\\+current\\b)|commit\\b|stash\\b|tag\\b)/",
"group": "inline@97",
@ -6609,6 +6624,11 @@
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.undoCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+HEAD\\b)(?=.*?\\b\\+unpublished\\b)/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.revert",
"when": "!gitlens:readonly && viewItem =~ /gitlens:commit\\b(?=.*?\\b\\+current\\b)/",
"group": "1_gitlens_actions@2"

+ 10
- 5
src/commands/git/reset.ts Целия файл

@ -33,6 +33,7 @@ interface State {
export interface ResetGitCommandArgs {
readonly command: 'reset';
confirm?: boolean;
state?: Partial<State>;
}
@ -53,13 +54,15 @@ export class ResetGitCommand extends QuickCommand {
this.initialState = {
counter: counter,
confirm: true,
confirm: args?.confirm ?? true,
...args?.state,
};
this._canSkipConfirm = !this.initialState.confirm;
}
private _canSkipConfirm: boolean = false;
get canSkipConfirm(): boolean {
return false;
return this._canSkipConfirm;
}
execute(state: ResetStepState) {
@ -138,10 +141,12 @@ export class ResetGitCommand extends QuickCommand {
state.reference = result;
}
const result = yield* this.confirmStep(state as ResetStepState, context);
if (result === StepResult.Break) continue;
if (this.confirm(state.confirm)) {
const result = yield* this.confirmStep(state as ResetStepState, context);
if (result === StepResult.Break) continue;
state.flags = result;
state.flags = result;
}
QuickCommand.endSteps(state);
this.execute(state as ResetStepState);

+ 8
- 2
src/commands/gitCommands.actions.ts Целия файл

@ -27,6 +27,7 @@ import {
Repository,
} from '../git/git';
import { GitUri } from '../git/gitUri';
import { ResetGitCommandArgs } from './git/reset';
export async function executeGitCommand(args: GitCommandsCommandArgs): Promise<void> {
void (await executeCommand<GitCommandsCommandArgs>(Commands.GitCommands, args));
@ -77,10 +78,15 @@ export namespace GitActions {
});
}
export function reset(repo?: string | Repository, ref?: GitRevisionReference) {
export function reset(
repo?: string | Repository,
ref?: GitRevisionReference,
flags?: NonNullable<ResetGitCommandArgs['state']>['flags'],
) {
return executeGitCommand({
command: 'reset',
state: { repo: repo, reference: ref },
confirm: flags == null || flags.includes('--hard'),
state: { repo: repo, reference: ref, flags: flags },
});
}

+ 18
- 3
src/views/nodes/branchNode.ts Целия файл

@ -15,6 +15,7 @@ import {
GitBranchReference,
GitLog,
GitRemoteType,
GitRevision,
PullRequestState,
} from '../../git/git';
import { GitUri } from '../../git/gitUri';
@ -160,8 +161,14 @@ export class BranchNode
new BranchTrackingStatusNode(this.view, this, this.branch, status, 'none', this.root),
);
}
} else if (pr != null) {
children.push(new PullRequestNode(this.view, this, pr, this.branch));
}
let unpublished: GitLog | undefined;
if (this.branch.tracking && this.branch.state.ahead) {
unpublished = await Container.git.getLog(this.uri.repoPath!, {
limit: 0,
ref: GitRevision.createRange(this.branch.tracking, 'HEAD'),
});
}
const getBranchAndTagTips = await Container.git.getBranchesAndTagsTipsFn(
@ -172,7 +179,15 @@ export class BranchNode
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitNode(this.view, this, c, this.branch, getBranchAndTagTips),
c =>
new CommitNode(
this.view,
this,
c,
unpublished?.commits.has(c.ref),
this.branch,
getBranchAndTagTips,
),
),
this,
),

+ 4
- 1
src/views/nodes/branchTrackingStatusNode.ts Целия файл

@ -81,7 +81,10 @@ export class BranchTrackingStatusNode extends ViewNode implement
const children = [
...insertDateMarkers(
Iterables.map(commits, c => new CommitNode(this.view, this, c, this.branch)),
Iterables.map(
commits,
c => new CommitNode(this.view, this, c, this.upstreamType === 'ahead', this.branch),
),
this,
1,
),

+ 2
- 2
src/views/nodes/commitFileNode.ts Целия файл

@ -92,8 +92,8 @@ export class CommitFileNode extends ViewRefFileNode {
private get description() {
return this._options.displayAsCommit
? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, {
messageTruncateAtNewLine: true,
dateFormat: Container.config.defaultDateFormat,
messageTruncateAtNewLine: true,
})
: StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, {
relativePath: this.relativePath,
@ -113,8 +113,8 @@ export class CommitFileNode extends ViewRefFileNode {
if (this._label === undefined) {
this._label = this._options.displayAsCommit
? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, {
messageTruncateAtNewLine: true,
dateFormat: Container.config.defaultDateFormat,
messageTruncateAtNewLine: true,
})
: StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, {
relativePath: this.relativePath,

+ 13
- 9
src/views/nodes/commitNode.ts Целия файл

@ -20,6 +20,7 @@ export class CommitNode extends ViewRefNode
view: ViewsWithFiles,
parent: ViewNode,
public readonly commit: GitLogCommit,
private readonly unpublished?: boolean,
public readonly branch?: GitBranch,
private readonly getBranchAndTagTips?: (sha: string) => string | undefined,
private readonly _options: { expand?: boolean } = {},
@ -39,9 +40,9 @@ export class CommitNode extends ViewRefNode
return CommitFormatter.fromTemplate(
this.commit.isUncommitted
? `\${author} ${GlyphChars.Dash} \${id}\n\${ago} (\${date})`
: `\${author}\${ (email)}\${" via "pullRequest} ${
GlyphChars.Dash
} \${id}\${ (tips)}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({
: `\${author}\${ (email)}\${" via "pullRequest} ${GlyphChars.Dash} \${id}${
this.unpublished ? ' (unpublished)' : ''
}\${ (tips)}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({
expand: true,
prefix: '\n\n',
separator: '\n',
@ -103,16 +104,19 @@ export class CommitNode extends ViewRefNode
this._options.expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
);
item.contextValue = `${ContextValues.Commit}${this.branch?.current ? '+current' : ''}`;
item.contextValue = `${ContextValues.Commit}${this.branch?.current ? '+current' : ''}${
this.branch?.current && this.branch.sha === this.commit.ref ? '+HEAD' : ''
}${this.unpublished ? '+unpublished' : ''}`;
item.description = CommitFormatter.fromTemplate(this.view.config.commitDescriptionFormat, this.commit, {
messageTruncateAtNewLine: true,
dateFormat: Container.config.defaultDateFormat,
messageTruncateAtNewLine: true,
});
item.iconPath =
!(this.view instanceof StashesView) && this.view.config.avatars
? this.commit.getAvatarUri(Container.config.defaultGravatarsStyle)
: new ThemeIcon('git-commit');
item.iconPath = this.unpublished
? new ThemeIcon('cloud-upload')
: !(this.view instanceof StashesView) && this.view.config.avatars
? this.commit.getAvatarUri(Container.config.defaultGravatarsStyle)
: new ThemeIcon('git-commit');
item.tooltip = this.tooltip;
return item;

+ 1
- 1
src/views/nodes/contributorNode.ts Целия файл

@ -47,7 +47,7 @@ export class ContributorNode extends ViewNode
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitNode(this.view, this, c, undefined, getBranchAndTagTips),
c => new CommitNode(this.view, this, c, undefined, undefined, getBranchAndTagTips),
),
this,
),

+ 1
- 1
src/views/nodes/resultsCommitsNode.ts Целия файл

@ -50,7 +50,7 @@ export class ResultsCommitsNode extends ViewNode implements Page
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitNode(this.view, this, c, undefined, getBranchAndTagTips, options),
c => new CommitNode(this.view, this, c, undefined, undefined, getBranchAndTagTips, options),
),
this,
undefined,

+ 1
- 1
src/views/nodes/tagNode.ts Целия файл

@ -50,7 +50,7 @@ export class TagNode extends ViewRefNode
...insertDateMarkers(
Iterables.map(
log.commits.values(),
c => new CommitNode(this.view, this, c, undefined, getBranchAndTagTips),
c => new CommitNode(this.view, this, c, undefined, undefined, getBranchAndTagTips),
),
this,
),

+ 16
- 0
src/views/viewCommands.ts Целия файл

@ -193,6 +193,7 @@ export class ViewCommands {
commands.registerCommand('gitlens.views.resetCommit', this.resetCommit, this);
commands.registerCommand('gitlens.views.resetToCommit', this.resetToCommit, this);
commands.registerCommand('gitlens.views.revert', this.revert, this);
commands.registerCommand('gitlens.views.undoCommit', this.undoCommit, this);
commands.registerCommand('gitlens.views.terminalRemoveRemote', this.terminalRemoveRemote, this);
}
@ -526,6 +527,21 @@ export class ViewCommands {
}
@debug()
private undoCommit(node: CommitNode) {
if (!(node instanceof CommitNode)) return Promise.resolve();
return GitActions.reset(
node.repoPath,
GitReference.create(`${node.ref.ref}^`, node.ref.repoPath, {
refType: 'revision',
name: `${node.ref.name}^`,
message: node.ref.message,
}),
['--soft'],
);
}
@debug()
private unsetAsDefault(node: RemoteNode) {
if (!(node instanceof RemoteNode)) return Promise.resolve();

Зареждане…
Отказ
Запис