Skip to content

Commit 15e7b0b

Browse files
committed
feat: generating diff works, finally
1 parent 9a9a970 commit 15e7b0b

2 files changed

Lines changed: 44 additions & 41 deletions

File tree

solid/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"start": "vite",
55
"dev": "vite",
66
"build": "vite build",
7+
"build:watch": "vite build --watch",
78
"serve": "vite preview"
89
},
910
"license": "MIT",

src/extension.ts

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22
import { GitExtension } from "./git";
33
import axios from "axios";
44
import { CodesyncWebviewProvider } from "./webviewProvider";
5+
import * as child_process from "child_process";
56

67
async function getGitAPI() {
78
try {
@@ -17,13 +18,6 @@ async function getGitAPI() {
1718
}
1819
}
1920

20-
// let diff: {
21-
// staged: Change[] | undefined;
22-
// unstaged: Change[] | undefined;
23-
// } = { staged: undefined, unstaged: undefined };
24-
25-
let diff: string = "";
26-
2721
export async function activate(context: vscode.ExtensionContext) {
2822
vscode.window.showInformationMessage("Codesync has started... Bruh!");
2923

@@ -38,45 +32,53 @@ export async function activate(context: vscode.ExtensionContext) {
3832

3933
context.subscriptions.push(
4034
vscode.commands.registerCommand("codesync.sendChanges", async () => {
41-
// const git = await getGitAPI();
42-
// const repositories = git?.repositories || [];
43-
// // TODO: check if multiple repos open
44-
// const repo = await git?.init(repositories[0].rootUri);
45-
46-
// // const staged = repo?.state.indexChanges || [];
47-
// // const unstaged = repo?.state.workingTreeChanges || [];
48-
// // const paths = [
49-
// // ...staged?.map((s) => s.uri.toString().replace("file://", "")),
50-
// // ...unstaged?.map((u) => u.uri.toString().replace("file://", "")),
51-
// // ];
52-
// // const repoPath = repo?.rootUri.fsPath || "";
53-
54-
// try {
55-
// await repo?.add([]);
56-
// } catch (e) {
57-
// console.error(e);
58-
// }
59-
60-
// diff = (await repo?.diff(true)) || "";
35+
const git = await getGitAPI();
36+
const repositories = git?.repositories || [];
37+
// TODO: should pick correct repo if multiple are open
38+
const repo = await git?.init(repositories[0].rootUri);
39+
40+
let cmd_add_to_index = `git status --porcelain | sed -r 's/^.{3}//' | while read line; do git add -N $line; done`;
41+
42+
const cwd = vscode.workspace.workspaceFolders![0].uri.fsPath;
43+
console.log(cwd);
44+
child_process.exec(
45+
cmd_add_to_index,
46+
{
47+
cwd,
48+
},
49+
(error, stdout, stderr) => {
50+
// TODO: move `| sed -r 's/^.{3}//' | while read line; do git add -N $line; done`
51+
// to here, to remove dependency on bash commands
52+
53+
if (error) {
54+
vscode.window.showErrorMessage(
55+
"Failed to create patch",
56+
error.message
57+
);
58+
} else {
59+
vscode.window.showInformationMessage(
60+
"Patch files created successfully"
61+
);
62+
}
63+
}
64+
);
65+
66+
const diff = {
67+
unstaged: "",
68+
staged: "",
69+
};
70+
diff.staged = (await repo?.diff(true)) || "";
71+
diff.unstaged = (await repo?.diff()) || "";
72+
73+
console.log("STAGE", diff.staged);
74+
console.log("UNSTAGE", diff.unstaged);
6175

6276
// const response = await axios.post("http://localhost:3000", {
63-
// diff: diff,
77+
// diff: diff,
6478
// });
6579
// console.log("response", response.data);
6680

67-
await vscode.commands.executeCommand(
68-
"workbench.view.extension.codesync-sidepanel-view"
69-
);
70-
// provider.show();
71-
72-
vscode.window.showInformationMessage(
73-
`finished`
74-
// `${
75-
// repositories.length && diff.length
76-
// ? "Changes saved'"
77-
// : "No repo or changes detected"
78-
// }`
79-
);
81+
vscode.window.showInformationMessage("Changes saved");
8082
})
8183
);
8284

0 commit comments

Comments
 (0)