Przeglądaj źródła

Fixes stashes with untracked files

main
Eric Amodio 4 lat temu
rodzic
commit
e7c18882df
3 zmienionych plików z 29 dodań i 26 usunięć
  1. +1
    -1
      src/git/models/logCommit.ts
  2. +20
    -1
      src/git/models/stashCommit.ts
  3. +8
    -24
      src/views/nodes/stashNode.ts

+ 1
- 1
src/git/models/logCommit.ts Wyświetl plik

@ -175,7 +175,7 @@ export class GitLogCommit extends GitCommit {
toFileCommit(file: string | GitFile): GitLogCommit | undefined {
const fileName = typeof file === 'string' ? GitUri.relativeTo(file, this.repoPath) : file.fileName;
const foundFile = this.files.find(f => f.fileName === fileName);
if (foundFile === undefined) return undefined;
if (foundFile == null) return undefined;
let sha;
// If this is a stash commit with an untracked file

+ 20
- 1
src/git/models/stashCommit.ts Wyświetl plik

@ -1,9 +1,10 @@
'use strict';
import { GitCommitType } from './commit';
import { Container } from '../../container';
import { GitFile } from './file';
import { GitLogCommit } from './logCommit';
import { GitReference } from './models';
import { memoize } from '../../system';
import { gate, memoize } from '../../system';
const stashNumberRegex = /stash@{(\d+)}/;
@ -49,6 +50,24 @@ export class GitStashCommit extends GitLogCommit {
return this.stashName;
}
private _untrackedFilesChecked = false;
@gate()
async checkForUntrackedFiles() {
if (!this._untrackedFilesChecked) {
this._untrackedFilesChecked = true;
// Check for any untracked files -- since git doesn't return them via `git stash list` :(
// See https://stackoverflow.com/questions/12681529/
const commit = await Container.git.getCommit(this.repoPath, `${this.stashName}^3`);
if (commit != null && commit.files.length !== 0) {
// Since these files are untracked -- make them look that way
commit.files.forEach(s => (s.status = '?'));
this.files.push(...commit.files);
}
}
}
with(changes: {
type?: GitCommitType;
sha?: string | null;

+ 8
- 24
src/views/nodes/stashNode.ts Wyświetl plik

@ -1,15 +1,12 @@
'use strict';
import * as paths from 'path';
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewFilesLayout } from '../../config';
import { Container } from '../../container';
import { CommitFormatter, GitStashCommit, GitStashReference } from '../../git/git';
import { Arrays, Iterables, Strings } from '../../system';
import { ContextValues, FileNode, FolderNode, RepositoryNode, StashFileNode, ViewNode, ViewRefNode } from '../nodes';
import { Arrays, Strings } from '../../system';
import { ViewsWithFiles } from '../viewBase';
import { StashFileNode } from './stashFileNode';
import { ContextValues, ViewNode, ViewRefNode } from './viewNode';
import { RepositoryNode } from './repositoryNode';
import { FileNode, FolderNode } from '../nodes';
import { ViewFilesLayout } from '../../config';
export class StashNode extends ViewRefNode<ViewsWithFiles, GitStashReference> {
static key = ':stash';
@ -34,25 +31,12 @@ export class StashNode extends ViewRefNode {
}
async getChildren(): Promise<ViewNode[]> {
let files = this.commit.files;
// Check for any untracked files -- since git doesn't return them via `git stash list` :(
// See https://stackoverflow.com/questions/12681529/
const log = await Container.git.getLog(this.commit.repoPath, {
limit: 1,
ref: `${this.commit.stashName}^3`,
});
if (log != null) {
const commit = Iterables.first(log.commits.values());
if (commit != null && commit.files.length !== 0) {
// Since these files are untracked -- make them look that way
commit.files.forEach(s => (s.status = '?'));
// Ensure we have checked for untracked files
await this.commit.checkForUntrackedFiles();
files = { ...files, ...commit.files };
}
}
let children: FileNode[] = files.map(s => new StashFileNode(this.view, this, s, this.commit.toFileCommit(s)!));
let children: FileNode[] = this.commit.files.map(
s => new StashFileNode(this.view, this, s, this.commit.toFileCommit(s)!),
);
if (this.view.config.files.layout !== ViewFilesLayout.List) {
const hierarchy = Arrays.makeHierarchical(

Ładowanie…
Anuluj
Zapisz