Skip to content

Commit fef12ca

Browse files
committed
Update commit log when a git action has occurred
When a commit happens or pull the log will update in the scm view. #3
1 parent 892e48a commit fef12ca

File tree

6 files changed

+85
-40
lines changed

6 files changed

+85
-40
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"name": "Richard Kotze",
1717
"email": "richkotze@outlook.com"
1818
},
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/rkotze/git-ease.git"
22+
},
1923
"homepage": "https://github.com/rkotze/git-ease/blob/trunk/README.md",
2024
"bugs": {
2125
"url": "https://github.com/rkotze/git-ease/issues"

src/extension.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { SidePanelProvider } from "./side-panel-provider";
66
// this method is called when your extension is activated
77
// your extension is activated the very first time the command is executed
88
export function activate(context: vscode.ExtensionContext) {
9-
109
const provider = new SidePanelProvider(context.extensionUri);
1110
context.subscriptions.push(
1211
vscode.window.registerWebviewViewProvider("git-ease.scm-panel", provider)

src/git/watch-for-commit.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
import { window } from "vscode";
4+
import { GitExt } from "../vscode-git-extension/git-ext";
5+
6+
export function watchForCommit(cb: Function): fs.FSWatcher | undefined {
7+
const gitExt = new GitExt();
8+
const gitCommit = path.join(gitExt.rootPath || "", ".git");
9+
10+
try {
11+
return fs.watch(gitCommit, function (evt, filename) {
12+
if (filename) {
13+
if (debounceFsWatch()) {
14+
return;
15+
}
16+
cb(evt);
17+
}
18+
});
19+
} catch (err) {
20+
window.showErrorMessage("Watch for commit failed!: " + err.message);
21+
}
22+
}
23+
24+
let fsWait: boolean | NodeJS.Timeout = false;
25+
function debounceFsWatch() {
26+
if (fsWait) {
27+
return true;
28+
}
29+
fsWait = setTimeout(() => {
30+
fsWait = false;
31+
}, 1000); // windows is a bit slower
32+
}

src/side-panel-provider.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { getNonce } from "./get-nonce";
3+
import { watchForCommit } from "./git/watch-for-commit";
34
import { copyCommitToInput } from "./messages/copy-commit-to-input";
45
import { gitLog } from "./messages/git-log";
56

@@ -31,6 +32,13 @@ export class SidePanelProvider implements vscode.WebviewViewProvider {
3132
return gitLog(webviewView);
3233
case "copyCommitToInput":
3334
return copyCommitToInput(data.args[0]);
35+
case "panelReady":
36+
watchForCommit(function () {
37+
setTimeout(function () {
38+
gitLog(webviewView);
39+
}, 500);
40+
});
41+
return gitLog(webviewView);
3442
}
3543
});
3644
}

src/webview/Commit.svelte

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,47 @@
2222
}
2323
</script>
2424

25+
<li class="commit">
26+
<div class="action-bar-toggle">
27+
<div class="title" on:click={toggleFullCommit}>
28+
<span class="author-border">
29+
<span
30+
class="author"
31+
title={`${commit.author.name} <${commit.author.email}>`}
32+
>{commit.author.initials}</span
33+
>
34+
</span>
35+
{parseMojis(commit.title)}
36+
</div>
37+
<div class="actions">
38+
<button
39+
class="octicon button"
40+
on:click={copyMessage}
41+
title="Copy commit message to input box">
42+
{@html octicons["inbox"].toSVG()}
43+
</button>
44+
</div>
45+
<div class="micro-info">
46+
<Badge type="clear">{relativeDate(commit.date)}</Badge>
47+
{#if commit.branch}
48+
<Badge type="green">{commit.branch}</Badge>
49+
{/if}
50+
</div>
51+
</div>
52+
53+
<div class="full-commit" class:open>
54+
<p class="body">
55+
<strong>{commit.title}</strong><br />
56+
{@html commit.body.replace(/\n/g, "<br />")}
57+
</p>
58+
<CommitMeta date={commit.date} hash={commit.hash} />
59+
<CommitAuthors author={commit.author} />
60+
</div>
61+
</li>
62+
2563
<style>
2664
:global(.vscode-dark) li.commit:hover {
27-
background-color: rgba(255, 255, 255, 0.2);
65+
background-color: rgba(255, 255, 255, 0.06);
2866
}
2967
:global(.vscode-dark) li.commit .title .author {
3068
background-color: #222;
@@ -33,7 +71,7 @@
3371
fill: #ccc;
3472
}
3573
:global(.vscode-light) li.commit:hover {
36-
background-color: rgba(0, 0, 0, 0.2);
74+
background-color: rgba(0, 0, 0, 0.06);
3775
}
3876
:global(.vscode-light) li.commit .title .author {
3977
background-color: #eee;
@@ -137,39 +175,3 @@
137175
line-height: 1.8em;
138176
}
139177
</style>
140-
141-
<li class="commit">
142-
<div class="action-bar-toggle">
143-
<div class="title" on:click={toggleFullCommit}>
144-
<span class="author-border">
145-
<span
146-
class="author"
147-
title={`${commit.author.name} <${commit.author.email}>`}>{commit.author.initials}</span>
148-
</span>
149-
{parseMojis(commit.title)}
150-
</div>
151-
<div class="actions">
152-
<button
153-
class="octicon button"
154-
on:click={copyMessage}
155-
title="Copy commit message to input box">
156-
{@html octicons['inbox'].toSVG()}
157-
</button>
158-
</div>
159-
<div class="micro-info">
160-
<Badge type="clear">{relativeDate(commit.date)}</Badge>
161-
{#if commit.branch}
162-
<Badge type="green">{commit.branch}</Badge>
163-
{/if}
164-
</div>
165-
</div>
166-
167-
<div class="full-commit" class:open>
168-
<p class="body">
169-
<strong>{commit.title}</strong><br />
170-
{@html commit.body.replace(/\n/g, '<br />')}
171-
</p>
172-
<CommitMeta date={commit.date} hash={commit.hash} />
173-
<CommitAuthors author={commit.author} />
174-
</div>
175-
</li>

src/webview/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ declare var acquireVsCodeApi: any;
66

77
const vscode = acquireVsCodeApi();
88

9-
vscode.postMessage({ command: "commitList" });
9+
vscode.postMessage({ command: "panelReady" });
1010

1111
new App({
1212
target: document.getElementById("app"),

0 commit comments

Comments
 (0)