Skip to content

Commit

Permalink
Update commit log when a git action has occurred
Browse files Browse the repository at this point in the history
When a commit happens or pull the log will update in the scm view.

#3
  • Loading branch information
rkotze committed Jan 17, 2021
1 parent 892e48a commit fef12ca
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 40 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"name": "Richard Kotze",
"email": "[email protected]"
},
"repository": {
"type": "git",
"url": "https://github.com/rkotze/git-ease.git"
},
"homepage": "https://github.com/rkotze/git-ease/blob/trunk/README.md",
"bugs": {
"url": "https://github.com/rkotze/git-ease/issues"
Expand Down
1 change: 0 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SidePanelProvider } from "./side-panel-provider";
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

const provider = new SidePanelProvider(context.extensionUri);
context.subscriptions.push(
vscode.window.registerWebviewViewProvider("git-ease.scm-panel", provider)
Expand Down
32 changes: 32 additions & 0 deletions src/git/watch-for-commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as fs from "fs";
import * as path from "path";
import { window } from "vscode";
import { GitExt } from "../vscode-git-extension/git-ext";

export function watchForCommit(cb: Function): fs.FSWatcher | undefined {
const gitExt = new GitExt();
const gitCommit = path.join(gitExt.rootPath || "", ".git");

try {
return fs.watch(gitCommit, function (evt, filename) {
if (filename) {
if (debounceFsWatch()) {
return;
}
cb(evt);
}
});
} catch (err) {
window.showErrorMessage("Watch for commit failed!: " + err.message);
}
}

let fsWait: boolean | NodeJS.Timeout = false;
function debounceFsWatch() {
if (fsWait) {
return true;
}
fsWait = setTimeout(() => {
fsWait = false;
}, 1000); // windows is a bit slower
}
8 changes: 8 additions & 0 deletions src/side-panel-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import { getNonce } from "./get-nonce";
import { watchForCommit } from "./git/watch-for-commit";
import { copyCommitToInput } from "./messages/copy-commit-to-input";
import { gitLog } from "./messages/git-log";

Expand Down Expand Up @@ -31,6 +32,13 @@ export class SidePanelProvider implements vscode.WebviewViewProvider {
return gitLog(webviewView);
case "copyCommitToInput":
return copyCommitToInput(data.args[0]);
case "panelReady":
watchForCommit(function () {
setTimeout(function () {
gitLog(webviewView);
}, 500);
});
return gitLog(webviewView);
}
});
}
Expand Down
78 changes: 40 additions & 38 deletions src/webview/Commit.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,47 @@
}
</script>

<li class="commit">
<div class="action-bar-toggle">
<div class="title" on:click={toggleFullCommit}>
<span class="author-border">
<span
class="author"
title={`${commit.author.name} <${commit.author.email}>`}
>{commit.author.initials}</span
>
</span>
{parseMojis(commit.title)}
</div>
<div class="actions">
<button
class="octicon button"
on:click={copyMessage}
title="Copy commit message to input box">
{@html octicons["inbox"].toSVG()}
</button>
</div>
<div class="micro-info">
<Badge type="clear">{relativeDate(commit.date)}</Badge>
{#if commit.branch}
<Badge type="green">{commit.branch}</Badge>
{/if}
</div>
</div>

<div class="full-commit" class:open>
<p class="body">
<strong>{commit.title}</strong><br />
{@html commit.body.replace(/\n/g, "<br />")}
</p>
<CommitMeta date={commit.date} hash={commit.hash} />
<CommitAuthors author={commit.author} />
</div>
</li>

<style>
:global(.vscode-dark) li.commit:hover {
background-color: rgba(255, 255, 255, 0.2);
background-color: rgba(255, 255, 255, 0.06);
}
:global(.vscode-dark) li.commit .title .author {
background-color: #222;
Expand All @@ -33,7 +71,7 @@
fill: #ccc;
}
:global(.vscode-light) li.commit:hover {
background-color: rgba(0, 0, 0, 0.2);
background-color: rgba(0, 0, 0, 0.06);
}
:global(.vscode-light) li.commit .title .author {
background-color: #eee;
Expand Down Expand Up @@ -137,39 +175,3 @@
line-height: 1.8em;
}
</style>

<li class="commit">
<div class="action-bar-toggle">
<div class="title" on:click={toggleFullCommit}>
<span class="author-border">
<span
class="author"
title={`${commit.author.name} <${commit.author.email}>`}>{commit.author.initials}</span>
</span>
{parseMojis(commit.title)}
</div>
<div class="actions">
<button
class="octicon button"
on:click={copyMessage}
title="Copy commit message to input box">
{@html octicons['inbox'].toSVG()}
</button>
</div>
<div class="micro-info">
<Badge type="clear">{relativeDate(commit.date)}</Badge>
{#if commit.branch}
<Badge type="green">{commit.branch}</Badge>
{/if}
</div>
</div>

<div class="full-commit" class:open>
<p class="body">
<strong>{commit.title}</strong><br />
{@html commit.body.replace(/\n/g, '<br />')}
</p>
<CommitMeta date={commit.date} hash={commit.hash} />
<CommitAuthors author={commit.author} />
</div>
</li>
2 changes: 1 addition & 1 deletion src/webview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare var acquireVsCodeApi: any;

const vscode = acquireVsCodeApi();

vscode.postMessage({ command: "commitList" });
vscode.postMessage({ command: "panelReady" });

new App({
target: document.getElementById("app"),
Expand Down

0 comments on commit fef12ca

Please sign in to comment.