Skip to content

Commit eaf632c

Browse files
author
Eric Amodio
committed
Adds uncommitted changes to timeline
1 parent 9cd22d0 commit eaf632c

2 files changed

Lines changed: 72 additions & 16 deletions

File tree

extensions/git/src/commands.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,14 +2332,20 @@ export class CommandCenter {
23322332
}
23332333

23342334
@command('git.openDiff', { repository: false })
2335-
async openDiff(uri: Uri, hash: string) {
2335+
async openDiff(uri: Uri, lhs: string, rhs: string) {
23362336
const basename = path.basename(uri.fsPath);
23372337

2338-
if (hash === '~') {
2339-
return commands.executeCommand('vscode.diff', toGitUri(uri, hash), toGitUri(uri, `HEAD`), `${basename} (Index)`);
2338+
let title;
2339+
if ((lhs === 'HEAD' || lhs === '~') && rhs === '') {
2340+
title = `${basename} (Working Tree)`;
2341+
}
2342+
else if (lhs === 'HEAD' && rhs === '~') {
2343+
title = `${basename} (Index)`;
2344+
} else {
2345+
title = `${basename} (${lhs.endsWith('^') ? `${lhs.substr(0, 8)}^` : lhs.substr(0, 8)}) \u27f7 ${basename} (${rhs.endsWith('^') ? `${rhs.substr(0, 8)}^` : rhs.substr(0, 8)})`;
23402346
}
23412347

2342-
return commands.executeCommand('vscode.diff', toGitUri(uri, `${hash}^`), toGitUri(uri, hash), `${basename} (${hash.substr(0, 8)}^) \u27f7 ${basename} (${hash.substr(0, 8)})`);
2348+
return commands.executeCommand('vscode.diff', toGitUri(uri, lhs), rhs === '' ? uri : toGitUri(uri, rhs), title);
23432349
}
23442350

23452351
private createCommand(id: string, key: string, method: Function, options: CommandOptions): (...args: any[]) => any {

extensions/git/src/timelineProvider.ts

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export class GitTimelineProvider implements TimelineProvider {
6262
this._repo = repo;
6363
this._repoStatusDate = new Date();
6464
this._repoDisposable = Disposable.from(
65-
repo.onDidChangeRepository(this.onRepositoryChanged, this),
66-
repo.onDidRunGitStatus(this.onRepositoryStatusChanged, this)
65+
repo.onDidChangeRepository(uri => this.onRepositoryChanged(repo, uri)),
66+
repo.onDidRunGitStatus(() => this.onRepositoryStatusChanged(repo))
6767
);
6868
}
6969

@@ -90,7 +90,7 @@ export class GitTimelineProvider implements TimelineProvider {
9090
item.command = {
9191
title: 'Open Diff',
9292
command: 'git.openDiff',
93-
arguments: [uri, c.hash]
93+
arguments: [uri, `${c.hash}^`, c.hash]
9494
};
9595

9696
return item;
@@ -124,15 +124,58 @@ export class GitTimelineProvider implements TimelineProvider {
124124
}
125125

126126
const item = new TimelineItem('Staged Changes', date.getTime());
127-
item.id = '~';
127+
item.id = 'index';
128128
// TODO[ECA]: Replace with a better icon -- reflecting its status maybe?
129129
item.iconPath = new (ThemeIcon as any)('git-commit');
130130
item.description = `${dateFormatter.fromNow()} \u2022 You`;
131131
item.detail = `You \u2014 Index\n${dateFormatter.fromNow()} (${dateFormatter.format('MMMM Do, YYYY h:mma')})\n${status}`;
132132
item.command = {
133133
title: 'Open Comparison',
134134
command: 'git.openDiff',
135-
arguments: [uri, '~']
135+
arguments: [uri, 'HEAD', '~']
136+
};
137+
138+
items.push(item);
139+
}
140+
141+
142+
const working = repo.workingTreeGroup.resourceStates.find(r => r.resourceUri.fsPath === uri.fsPath);
143+
if (working) {
144+
const date = new Date();
145+
dateFormatter = dayjs(date);
146+
147+
let status;
148+
switch (working.type) {
149+
case Status.INDEX_MODIFIED:
150+
status = 'Modified';
151+
break;
152+
case Status.INDEX_ADDED:
153+
status = 'Added';
154+
break;
155+
case Status.INDEX_DELETED:
156+
status = 'Deleted';
157+
break;
158+
case Status.INDEX_RENAMED:
159+
status = 'Renamed';
160+
break;
161+
case Status.INDEX_COPIED:
162+
status = 'Copied';
163+
break;
164+
default:
165+
status = '';
166+
break;
167+
}
168+
169+
const item = new TimelineItem('Uncommited Changes', date.getTime());
170+
item.id = 'working';
171+
// TODO[ECA]: Replace with a better icon -- reflecting its status maybe?
172+
item.iconPath = new (ThemeIcon as any)('git-commit');
173+
item.description = `${dateFormatter.fromNow()} \u2022 You`;
174+
item.detail = `You \u2014 Working Tree\n${dateFormatter.fromNow()} (${dateFormatter.format('MMMM Do, YYYY h:mma')})\n${status}`;
175+
item.command = {
176+
title: 'Open Comparison',
177+
command: 'git.openDiff',
178+
arguments: [uri, index ? '~' : 'HEAD', '']
136179
};
137180

138181
items.push(item);
@@ -141,23 +184,30 @@ export class GitTimelineProvider implements TimelineProvider {
141184
return items;
142185
}
143186

144-
@debounce(500)
145187
private onRepositoriesChanged(_repo: Repository) {
146188
// console.log(`GitTimelineProvider.onRepositoriesChanged`);
147189

148190
// TODO[ECA]: Being naive for now and just always refreshing each time there is a new repository
149-
this._onDidChange.fire();
191+
this.fireChanged();
150192
}
151193

152-
@debounce(500)
153-
private onRepositoryChanged() {
154-
// console.log(`GitTimelineProvider.onRepositoryChanged`);
194+
private onRepositoryChanged(_repo: Repository, _uri: Uri) {
195+
// console.log(`GitTimelineProvider.onRepositoryChanged: uri=${uri.toString(true)}`);
155196

156-
this._onDidChange.fire();
197+
this.fireChanged();
157198
}
158199

159-
private onRepositoryStatusChanged() {
200+
private onRepositoryStatusChanged(_repo: Repository) {
201+
// console.log(`GitTimelineProvider.onRepositoryStatusChanged`);
202+
160203
// This is crappy, but for now just save the last time a status was run and use that as the timestamp for staged items
161204
this._repoStatusDate = new Date();
205+
206+
this.fireChanged();
207+
}
208+
209+
@debounce(500)
210+
private fireChanged() {
211+
this._onDidChange.fire();
162212
}
163213
}

0 commit comments

Comments
 (0)