Parcourir la source

Fixes path formatting & adds optional suffix

main
Eric Amodio il y a 6 ans
Parent
révision
26fc11f9df
8 fichiers modifiés avec 61 ajouts et 60 suppressions
  1. +3
    -3
      src/commands/diffWithRevision.ts
  2. +3
    -3
      src/commands/openFileRevision.ts
  3. +3
    -3
      src/commands/showQuickFileHistory.ts
  4. +1
    -1
      src/git/formatters/statusFormatter.ts
  5. +11
    -16
      src/git/gitUri.ts
  6. +2
    -2
      src/git/models/commit.ts
  7. +8
    -8
      src/git/models/logCommit.ts
  8. +30
    -24
      src/git/models/status.ts

+ 3
- 3
src/commands/diffWithRevision.ts Voir le fichier

@ -35,9 +35,9 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri);
const placeHolder = `Compare ${gitUri.getFormattedPath(
args.branchOrTag ? ` (${args.branchOrTag.name})${Strings.pad(GlyphChars.Dot, 2, 2)}` : undefined
)}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''} with revision${
const placeHolder = `Compare ${gitUri.getFormattedPath({
suffix: args.branchOrTag ? ` (${args.branchOrTag.name})` : undefined
})}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''} with revision${
GlyphChars.Ellipsis
}`;

+ 3
- 3
src/commands/openFileRevision.ts Voir le fichier

@ -65,9 +65,9 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri);
const placeHolder = `Open revision of ${gitUri.getFormattedPath(
args.branchOrTag ? ` (${args.branchOrTag.name})${Strings.pad(GlyphChars.Dot, 2, 2)}` : undefined
)}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}${
const placeHolder = `Open revision of ${gitUri.getFormattedPath({
suffix: args.branchOrTag ? ` (${args.branchOrTag.name})` : undefined
})}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}${
GlyphChars.Ellipsis
}`;

+ 3
- 3
src/commands/showQuickFileHistory.ts Voir le fichier

@ -39,9 +39,9 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
args = { ...args };
const placeHolder = `${gitUri.getFormattedPath(
args.branchOrTag ? ` (${args.branchOrTag.name})${Strings.pad(GlyphChars.Dot, 2, 2)}` : undefined
)}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
const placeHolder = `${gitUri.getFormattedPath({
suffix: args.branchOrTag ? ` (${args.branchOrTag.name})` : undefined
})}${gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''}`;
const progressCancellation = FileHistoryQuickPick.showProgress(placeHolder);
try {

+ 1
- 1
src/git/formatters/statusFormatter.ts Voir le fichier

@ -30,7 +30,7 @@ export class StatusFileFormatter extends Formatter
}
get filePath() {
const filePath = GitStatusFile.getFormattedPath(this._item, undefined, this._options.relativePath);
const filePath = GitStatusFile.getFormattedPath(this._item, { relativeTo: this._options.relativePath });
return this._padOrTruncate(filePath, this._options.tokenOptions!.filePath);
}

+ 11
- 16
src/git/gitUri.ts Voir le fichier

@ -113,19 +113,11 @@ export class GitUri extends ((Uri as any) as UriEx) {
return path.basename(path.relative(this.repoPath || '', this.fsPath), relativeTo);
}
getFormattedPath(separator: string = Strings.pad(GlyphChars.Dot, 2, 2), relativeTo?: string): string {
let directory = path.dirname(this.fsPath);
if (this.repoPath) {
directory = path.relative(this.repoPath, directory);
}
if (relativeTo !== undefined) {
directory = path.relative(relativeTo, directory);
}
directory = Strings.normalizePath(directory);
getFormattedPath(options: { relativeTo?: string; separator?: string; suffix?: string } = {}): string {
const { relativeTo = this.repoPath, separator = Strings.pad(GlyphChars.Dot, 2, 2), suffix = '' } = options;
return !directory || directory === '.'
? path.basename(this.fsPath)
: `${path.basename(this.fsPath)}${separator}${directory}`;
const directory = GitUri.getDirectory(this.fsPath, relativeTo);
return `${path.basename(this.fsPath)}${suffix}${directory ? `${separator}${directory}` : ''}`;
}
getRelativePath(relativeTo?: string): string {
@ -231,12 +223,13 @@ export class GitUri extends ((Uri as any) as UriEx) {
static getFormattedPath(
fileNameOrUri: string | Uri,
separator: string = Strings.pad(GlyphChars.Dot, 2, 2),
relativeTo?: string
options: { relativeTo?: string; separator?: string; suffix?: string } = {}
): string {
const { relativeTo, separator = Strings.pad(GlyphChars.Dot, 2, 2), suffix = '' } = options;
let fileName: string;
if (fileNameOrUri instanceof Uri) {
if (fileNameOrUri instanceof GitUri) return fileNameOrUri.getFormattedPath(separator, relativeTo);
if (fileNameOrUri instanceof GitUri) return fileNameOrUri.getFormattedPath(options);
fileName = fileNameOrUri.fsPath;
}
@ -245,7 +238,9 @@ export class GitUri extends ((Uri as any) as UriEx) {
}
const directory = GitUri.getDirectory(fileName, relativeTo);
return !directory ? path.basename(fileName) : `${path.basename(fileName)}${separator}${directory}`;
return !directory
? `${path.basename(fileName)}${suffix}`
: `${path.basename(fileName)}${suffix}${separator}${directory}`;
}
static getRelativePath(fileNameOrUri: string | Uri, relativeTo?: string, repoPath?: string): string {

+ 2
- 2
src/git/models/commit.ts Voir le fichier

@ -176,8 +176,8 @@ export abstract class GitCommit {
return this._dateFormatter.fromNow();
}
getFormattedPath(separator: string = Strings.pad(GlyphChars.Dot, 2, 2)): string {
return GitUri.getFormattedPath(this.fileName, separator);
getFormattedPath(options: { relativeTo?: string; separator?: string; suffix?: string } = {}): string {
return GitUri.getFormattedPath(this.fileName, options);
}
getGravatarUri(fallback: GravatarDefaultStyle, size: number = 16): Uri {

+ 8
- 8
src/git/models/logCommit.ts Voir le fichier

@ -107,24 +107,24 @@ export class GitLogCommit extends GitCommit {
const { added, changed, deleted } = this.getDiffStatus();
if (added === 0 && changed === 0 && deleted === 0) return options.empty || '';
options = { empty: '', prefix: '', separator: ' ', suffix: '', ...options };
if (options.expand) {
const { compact, expand, prefix = '', separator = ' ', suffix = '' } = options;
if (expand) {
let status = '';
if (added) {
status += `${Strings.pluralize('file', added)} added`;
}
if (changed) {
status += `${status === '' ? '' : options.separator}${Strings.pluralize('file', changed)} changed`;
status += `${status === '' ? '' : separator}${Strings.pluralize('file', changed)} changed`;
}
if (deleted) {
status += `${status === '' ? '' : options.separator}${Strings.pluralize('file', deleted)} deleted`;
status += `${status === '' ? '' : separator}${Strings.pluralize('file', deleted)} deleted`;
}
return `${options.prefix}${status}${options.suffix}`;
return `${prefix}${status}${suffix}`;
}
return `${options.prefix}${options.compact && added === 0 ? '' : `+${added}${options.separator}`}${
options.compact && changed === 0 ? '' : `~${changed}${options.separator}`
}${options.compact && deleted === 0 ? '' : `-${deleted}`}${options.suffix}`;
return `${prefix}${compact && added === 0 ? '' : `+${added}${separator}`}${
compact && changed === 0 ? '' : `~${changed}${separator}`
}${compact && deleted === 0 ? '' : `-${deleted}`}${suffix}`;
}
toFileCommit(fileName: string): GitLogCommit | undefined;

+ 30
- 24
src/git/models/status.ts Voir le fichier

@ -81,52 +81,58 @@ export class GitStatus {
const { added, changed, deleted } = this.getDiffStatus();
if (added === 0 && changed === 0 && deleted === 0) return options.empty || '';
options = { empty: '', prefix: '', separator: ' ', suffix: '', ...options };
if (options.expand) {
const { compact, expand, prefix = '', separator = ' ', suffix = '' } = options;
if (expand) {
let status = '';
if (added) {
status += `${Strings.pluralize('file', added)} added`;
}
if (changed) {
status += `${status === '' ? '' : options.separator}${Strings.pluralize('file', changed)} changed`;
status += `${status === '' ? '' : separator}${Strings.pluralize('file', changed)} changed`;
}
if (deleted) {
status += `${status === '' ? '' : options.separator}${Strings.pluralize('file', deleted)} deleted`;
status += `${status === '' ? '' : separator}${Strings.pluralize('file', deleted)} deleted`;
}
return `${options.prefix}${status}${options.suffix}`;
return `${prefix}${status}${suffix}`;
}
return `${options.prefix}${options.compact && added === 0 ? '' : `+${added}${options.separator}`}${
options.compact && changed === 0 ? '' : `~${changed}${options.separator}`
}${options.compact && deleted === 0 ? '' : `-${deleted}`}${options.suffix}`;
return `${prefix}${compact && added === 0 ? '' : `+${added}${separator}`}${
compact && changed === 0 ? '' : `~${changed}${separator}`
}${compact && deleted === 0 ? '' : `-${deleted}`}${suffix}`;
}
getUpstreamStatus(options: { empty?: string; expand?: boolean; prefix?: string; separator?: string }): string {
getUpstreamStatus(options: {
empty?: string;
expand?: boolean;
prefix?: string;
separator?: string;
suffix?: string;
}): string {
return GitStatus.getUpstreamStatus(this.upstream, this.state, options);
}
static getUpstreamStatus(
upstream: string | undefined,
state: { ahead: number; behind: number },
options: { empty?: string; expand?: boolean; prefix?: string; separator?: string } = {}
options: { empty?: string; expand?: boolean; prefix?: string; separator?: string; suffix?: string } = {}
): string {
options = { empty: '', prefix: '', separator: ' ', ...options };
if (upstream === undefined || (state.behind === 0 && state.ahead === 0)) return options.empty!;
if (upstream === undefined || (state.behind === 0 && state.ahead === 0)) return options.empty || '';
if (options.expand) {
const { expand, prefix = '', separator = ' ', suffix = '' } = options;
if (expand) {
let status = '';
if (state.behind) {
status += `${Strings.pluralize('commit', state.behind)} behind`;
}
if (state.ahead) {
status += `${status === '' ? '' : options.separator}${Strings.pluralize('commit', state.ahead)} ahead`;
status += `${status === '' ? '' : separator}${Strings.pluralize('commit', state.ahead)} ahead`;
}
return `${options.prefix}${status}`;
return `${prefix}${status}${suffix}`;
}
return `${options.prefix}${state.behind}${GlyphChars.ArrowDown}${options.separator}${state.ahead}${
return `${prefix}${state.behind}${GlyphChars.ArrowDown}${separator}${state.ahead}${
GlyphChars.ArrowUp
}`;
}${suffix}`;
}
}
@ -134,10 +140,11 @@ export declare type GitStatusFileStatus = '!' | '?' | 'A' | 'C' | 'D' | 'M' | 'R
export interface IGitStatusFile {
status: GitStatusFileStatus;
readonly repoPath: string;
readonly indexStatus: GitStatusFileStatus;
readonly workTreeStatus: GitStatusFileStatus;
readonly fileName: string;
readonly originalFileName?: string;
readonly workTreeStatus: GitStatusFileStatus;
readonly indexStatus: GitStatusFileStatus;
}
export interface IGitStatusFileWithCommit extends IGitStatusFile {
@ -169,8 +176,8 @@ export class GitStatusFile implements IGitStatusFile {
return GitStatusFile.getFormattedDirectory(this, includeOriginal);
}
getFormattedPath(separator: string = Strings.pad(GlyphChars.Dot, 2, 2)): string {
return GitStatusFile.getFormattedPath(this, separator);
getFormattedPath(options: { relativeTo?: string; separator?: string; suffix?: string } = {}): string {
return GitStatusFile.getFormattedPath(this, options);
}
getOcticon() {
@ -214,10 +221,9 @@ export class GitStatusFile implements IGitStatusFile {
static getFormattedPath(
status: IGitStatusFile,
separator: string = Strings.pad(GlyphChars.Dot, 2, 2),
relativeTo?: string
options: { relativeTo?: string; separator?: string; suffix?: string } = {}
): string {
return GitUri.getFormattedPath(status.fileName, separator, relativeTo);
return GitUri.getFormattedPath(status.fileName, options);
}
static getRelativePath(status: IGitStatusFile, relativeTo?: string): string {

Chargement…
Annuler
Enregistrer