mirror of
https://github.com/kahole/edamagit.git
synced 2024-09-11 07:15:31 +03:00
untracked files
This commit is contained in:
parent
ba002cb6cd
commit
e82e8a8737
@ -1,7 +1,7 @@
|
||||
{
|
||||
"folding": {
|
||||
"markers": {
|
||||
"start": "^(Unstaged changes)|(Staged changes)|(Recent commits)",
|
||||
"start": "^(Untracked files)|((Unstaged|Staged) changes)|(Recent commits)",
|
||||
"end": "^\\.$"
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-branch",
|
||||
"command": "extension.magit-key-b",
|
||||
"title": "Magit Branch",
|
||||
"when": "editorLangId == magit-status"
|
||||
}
|
||||
@ -37,8 +37,8 @@
|
||||
"when": "editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-branch",
|
||||
"when": "editorLangId == magit-status"
|
||||
"command": "extension.magit-key-b",
|
||||
"when": "false && editorLangId == magit-status"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -69,7 +69,7 @@
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
},
|
||||
{
|
||||
"command": "extension.magit-branch",
|
||||
"command": "extension.magit-key-b",
|
||||
"key": "b",
|
||||
"when": "editorTextFocus && editorLangId == magit-status"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { MagitStatus } from "../model/magitStatus";
|
||||
import { MagitState } from "../model/magitStatus";
|
||||
|
||||
// export async function magitStatus() : Promise<MagitStatus> {
|
||||
// return {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as vscode from 'vscode';
|
||||
import StatusDocument from './documents/statusDocument';
|
||||
import { MagitStatus } from './model/magitStatus';
|
||||
import { magitStatuses } from './extension';
|
||||
import { MagitState } from './model/magitStatus';
|
||||
import { magitStates } from './extension';
|
||||
|
||||
export default class ContentProvider implements vscode.TextDocumentContentProvider {
|
||||
|
||||
@ -47,7 +47,7 @@ export default class ContentProvider implements vscode.TextDocumentContentProvid
|
||||
// `reference provider` command (https://code.visualstudio.com/api/references/commands).
|
||||
// From the result create a references document which is in charge of loading,
|
||||
// printing, and formatting references
|
||||
let document = new StatusDocument(uri, magitStatuses[uri.query], this._onDidChange);
|
||||
let document = new StatusDocument(uri, magitStates[uri.query], this._onDidChange);
|
||||
|
||||
this._documents.set(uri.query, document);
|
||||
return document.value;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { MagitStatus } from '../model/magitStatus';
|
||||
import { MagitState, Change } from '../model/magitStatus';
|
||||
import { Status } from '../typings/git';
|
||||
|
||||
export default class StatusDocument {
|
||||
|
||||
@ -10,7 +11,7 @@ export default class StatusDocument {
|
||||
|
||||
private readonly SECTION_FOLD_REGION_END: string = '.';
|
||||
|
||||
constructor(uri: vscode.Uri, magitStatus: MagitStatus, emitter: vscode.EventEmitter<vscode.Uri>) {
|
||||
constructor(uri: vscode.Uri, magitStatus: MagitState, emitter: vscode.EventEmitter<vscode.Uri>) {
|
||||
this._uri = uri;
|
||||
|
||||
// The ReferencesDocument has access to the event emitter from
|
||||
@ -23,24 +24,23 @@ export default class StatusDocument {
|
||||
this._lines.push(`Head: ${magitStatus._state.HEAD!.name} ${magitStatus.commitCache[magitStatus._state.HEAD!.commit!].message}`);
|
||||
this._lines.push('');
|
||||
|
||||
if (magitStatus.untrackedFiles) {
|
||||
this._lines.push(`Untracked files (${magitStatus.untrackedFiles.length})`);
|
||||
let untrackedFiles = this.renderChanges(magitStatus.untrackedFiles);
|
||||
this._lines.push(...untrackedFiles);
|
||||
this._lines.push(this.SECTION_FOLD_REGION_END);
|
||||
}
|
||||
|
||||
if (magitStatus.workingTreeChanges) {
|
||||
|
||||
this._lines.push(`Unstaged changes (${magitStatus._state.workingTreeChanges.length})`);
|
||||
|
||||
let unstagedChanges = magitStatus.workingTreeChanges
|
||||
.map(change => change.uri.path + "\n" + change.diff);
|
||||
|
||||
this._lines.push(`Unstaged changes (${magitStatus.workingTreeChanges.length})`);
|
||||
let unstagedChanges = this.renderChanges(magitStatus.workingTreeChanges);
|
||||
this._lines.push(...unstagedChanges);
|
||||
this._lines.push(this.SECTION_FOLD_REGION_END);
|
||||
}
|
||||
|
||||
if (magitStatus.indexChanges) {
|
||||
|
||||
this._lines.push(`Staged changes (${magitStatus._state.indexChanges.length})`);
|
||||
|
||||
let stagedChanges = magitStatus.indexChanges
|
||||
.map(change => change.uri.path + "\n" + change.diff);
|
||||
|
||||
this._lines.push(`Staged changes (${magitStatus.indexChanges.length})`);
|
||||
let stagedChanges = this.renderChanges(magitStatus.indexChanges);
|
||||
this._lines.push(...stagedChanges);
|
||||
this._lines.push(this.SECTION_FOLD_REGION_END);
|
||||
}
|
||||
@ -57,7 +57,33 @@ export default class StatusDocument {
|
||||
this._lines.push('');
|
||||
}
|
||||
|
||||
private renderChanges(changes: Change[]) : string[] {
|
||||
return changes
|
||||
.map(change => `${mapFileStatusToLabel(change.status)} ${change.uri.path}${change.diff ? '\n' + change.diff : ''}`);
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this._lines.join('\n');
|
||||
}
|
||||
}
|
||||
|
||||
function mapFileStatusToLabel(status: Status): string {
|
||||
switch (status) {
|
||||
case Status.INDEX_MODIFIED:
|
||||
case Status.MODIFIED:
|
||||
return "modified";
|
||||
case Status.INDEX_ADDED:
|
||||
return "added";
|
||||
case Status.INDEX_DELETED:
|
||||
case Status.DELETED:
|
||||
return "deleted";
|
||||
case Status.INDEX_RENAMED:
|
||||
return "renamed";
|
||||
case Status.INDEX_COPIED:
|
||||
return "copied";
|
||||
case Status.UNTRACKED:
|
||||
return "";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
@ -1,20 +1,22 @@
|
||||
import { workspace, languages, window, extensions, commands, ExtensionContext, Disposable, ViewColumn, FileChangeType } from 'vscode';
|
||||
import ContentProvider, { encodeLocation } from './contentProvider';
|
||||
import { GitExtension } from './typings/git';
|
||||
import { InflateStatus, MagitStatus } from './model/magitStatus';
|
||||
import { MagitStatus, MagitState } from './model/magitStatus';
|
||||
import { isDescendant } from './util';
|
||||
|
||||
export let magitStatuses: {[id: string]: MagitStatus} = {};
|
||||
export let magitStates: {[id: string]: MagitState} = {};
|
||||
|
||||
export function activate(context: ExtensionContext) {
|
||||
|
||||
if (workspace.workspaceFolders && workspace.workspaceFolders[0]) {
|
||||
|
||||
let gitExtension = extensions.getExtension<GitExtension>('vscode.git')!.exports;
|
||||
if (!gitExtension.enabled) {
|
||||
throw new Error("vscode.git Git extension not enabled");
|
||||
}
|
||||
const gitApi = gitExtension.getAPI(1);
|
||||
|
||||
const rootPath = workspace.workspaceFolders[0].uri.fsPath;
|
||||
|
||||
const repository = gitApi.repositories.filter(r => isDescendant(r.rootUri.fsPath, rootPath))[0];
|
||||
|
||||
const provider = new ContentProvider();
|
||||
@ -24,15 +26,12 @@ export function activate(context: ExtensionContext) {
|
||||
);
|
||||
|
||||
let disposable = commands.registerCommand('extension.magit', async () => {
|
||||
|
||||
const uri = encodeLocation(rootPath);
|
||||
|
||||
InflateStatus(repository)
|
||||
MagitStatus(repository)
|
||||
.then(m => {
|
||||
magitStatuses[uri.query] = m;
|
||||
|
||||
magitStates[uri.query] = m;
|
||||
workspace.openTextDocument(uri).then(doc => window.showTextDocument(doc, ViewColumn.Beside));
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,22 +1,21 @@
|
||||
import { RepositoryState, Commit, Repository, Status, Change as GitChange } from "../typings/git";
|
||||
import { RepositoryState, Commit, Repository, Change as GitChange, Status } from "../typings/git";
|
||||
|
||||
export interface Change extends GitChange {
|
||||
diff?: string;
|
||||
}
|
||||
|
||||
export interface MagitStatus {
|
||||
_state: RepositoryState;
|
||||
export interface MagitState {
|
||||
_state: RepositoryState; // TODO: shouldnt need this?
|
||||
readonly stashes?: Commit[];
|
||||
readonly log?: Commit[];
|
||||
readonly commitCache: { [id: string]: Commit; };
|
||||
readonly commitCache: { [id: string]: Commit; }; // TODO: rigid model with everything needed better?
|
||||
readonly workingTreeChanges?: Change[];
|
||||
readonly indexChanges?: Change[];
|
||||
readonly mergeChanges?: Change[];
|
||||
// test:
|
||||
readonly untrackedDiffTestProperty: string;
|
||||
readonly untrackedFiles?: Change[];
|
||||
}
|
||||
|
||||
export async function InflateStatus(repository: Repository): Promise<MagitStatus> {
|
||||
export async function MagitStatus(repository: Repository): Promise<MagitState> {
|
||||
|
||||
await repository.status();
|
||||
|
||||
@ -27,9 +26,22 @@ export async function InflateStatus(repository: Repository): Promise<MagitStatus
|
||||
.map(c => repository.getCommit(c)));
|
||||
// .map(repository.getCommit));
|
||||
|
||||
let workingTreeChangesTasks = Promise.all(repository.state.workingTreeChanges
|
||||
let untrackedFiles: Change[] = [];
|
||||
|
||||
let workingTreeChanges_NoUntracked = repository.state.workingTreeChanges
|
||||
.filter( c => {
|
||||
if (c.status === Status.UNTRACKED) {
|
||||
untrackedFiles.push(c);
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
let workingTreeChangesTasks = Promise.all(workingTreeChanges_NoUntracked
|
||||
.map(change =>
|
||||
repository.diffWithHEAD(change.uri.path)
|
||||
.then(getOnlyChunksFromDiff)
|
||||
.then<Change>(diff => {
|
||||
let magitChange: Change = change;
|
||||
magitChange.diff = diff;
|
||||
@ -37,15 +49,16 @@ export async function InflateStatus(repository: Repository): Promise<MagitStatus
|
||||
})
|
||||
));
|
||||
|
||||
let indexChangesTasks = Promise.all(repository.state.indexChanges
|
||||
.map(change =>
|
||||
repository.diffIndexWithHEAD(change.uri.path)
|
||||
.then<Change>(diff => {
|
||||
let magitChange: Change = change;
|
||||
magitChange.diff = diff;
|
||||
return magitChange;
|
||||
})
|
||||
));
|
||||
let indexChangesTasks = Promise.all(repository.state.indexChanges
|
||||
.map(change =>
|
||||
repository.diffIndexWithHEAD(change.uri.path)
|
||||
.then(getOnlyChunksFromDiff)
|
||||
.then<Change>(diff => {
|
||||
let magitChange: Change = change;
|
||||
magitChange.diff = diff;
|
||||
return magitChange;
|
||||
})
|
||||
));
|
||||
|
||||
let [log, commits, workingTreeChanges, indexChanges] =
|
||||
await Promise.all([
|
||||
@ -65,6 +78,23 @@ export async function InflateStatus(repository: Repository): Promise<MagitStatus
|
||||
workingTreeChanges,
|
||||
indexChanges,
|
||||
mergeChanges: undefined,
|
||||
untrackedDiffTestProperty: ""
|
||||
untrackedFiles
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getOnlyChunksFromDiff(diff: string): string {
|
||||
return diff.substring(diff.indexOf("@@"));
|
||||
}
|
||||
|
||||
// function inflateChanges(changes: GitChange[]) : Promise<Change[]> {
|
||||
// return Promise.all(changes
|
||||
// .map(change =>
|
||||
// repository.diffIndexWithHEAD(change.uri.path)
|
||||
// .then(getOnlyChunksFromDiff)
|
||||
// .then<Change>(diff => {
|
||||
// let magitChange: Change = change;
|
||||
// magitChange.diff = diff;
|
||||
// return magitChange;
|
||||
// })
|
||||
// ));
|
||||
// }
|
@ -6,7 +6,7 @@
|
||||
"patterns": [{ "include": "#sectionHeader" }, { "include": "#branchName" }]
|
||||
},
|
||||
"sectionHeader": {
|
||||
"match": "((Unstaged|Staged) changes)|Recent commits",
|
||||
"match": "Untracked files|((Unstaged|Staged) changes)|Recent commits",
|
||||
"name": "keyword.sectionHeader",
|
||||
"comment": ";; kan bruke markup.bold.sectionHeader"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user