Skip to content

Commit 8f860fd

Browse files
committed
Fix push command
1 parent 2a9d3c3 commit 8f860fd

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

src/commands/new.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,7 @@ syncode status
311311
syncode sync
312312
313313
# Push to remote
314-
git add .
315-
git commit -m "Update configs"
316-
git push
314+
syncode push
317315
\`\`\`
318316
`;
319317
writeFileSync(join(repoPath, "README.md"), readmeContent);
@@ -363,7 +361,7 @@ Next steps:
363361
• Edit configs in ${contractHome(repoPath)}/configs/
364362
• Changes are synced automatically via symlinks
365363
• Run 'syncode sync' to apply changes to your system
366-
${remote ? `• Push to GitHub: cd ${contractHome(repoPath)} && git push -u origin main` : ""}`,
364+
• Run 'syncode push' to commit and push changes`,
367365
);
368366
} catch (error) {
369367
p.cancel(`Failed to create configuration: ${error}`);

src/utils/git.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { REPO_ROOT } from "./paths";
1+
import { getRepoRoot, REPO_ROOT } from "./paths";
22
import { exec } from "./shell";
33

44
export async function isGitRepo(): Promise<boolean> {
5+
const repoRoot = getRepoRoot();
56
const result = await exec(
6-
`git -C "${REPO_ROOT}" rev-parse --is-inside-work-tree`,
7+
`git -C "${repoRoot}" rev-parse --is-inside-work-tree`,
78
);
89
return result.success;
910
}
1011

1112
export async function getGitStatus(): Promise<string> {
12-
const result = await exec(`git -C "${REPO_ROOT}" status --short`);
13+
const repoRoot = getRepoRoot();
14+
const result = await exec(`git -C "${repoRoot}" status --short`);
1315
return result.stdout;
1416
}
1517

@@ -19,68 +21,79 @@ export async function hasChanges(): Promise<boolean> {
1921
}
2022

2123
export async function getUntrackedFiles(): Promise<string[]> {
24+
const repoRoot = getRepoRoot();
2225
const result = await exec(
23-
`git -C "${REPO_ROOT}" ls-files --others --exclude-standard`,
26+
`git -C "${repoRoot}" ls-files --others --exclude-standard`,
2427
);
2528
if (!result.success || !result.stdout) return [];
2629
return result.stdout.split("\n").filter(Boolean);
2730
}
2831

2932
export async function getModifiedFiles(): Promise<string[]> {
30-
const result = await exec(`git -C "${REPO_ROOT}" diff --name-only`);
33+
const repoRoot = getRepoRoot();
34+
const result = await exec(`git -C "${repoRoot}" diff --name-only`);
3135
if (!result.success || !result.stdout) return [];
3236
return result.stdout.split("\n").filter(Boolean);
3337
}
3438

3539
export async function getStagedFiles(): Promise<string[]> {
36-
const result = await exec(`git -C "${REPO_ROOT}" diff --cached --name-only`);
40+
const repoRoot = getRepoRoot();
41+
const result = await exec(`git -C "${repoRoot}" diff --cached --name-only`);
3742
if (!result.success || !result.stdout) return [];
3843
return result.stdout.split("\n").filter(Boolean);
3944
}
4045

4146
export async function stageAll(): Promise<boolean> {
42-
const result = await exec(`git -C "${REPO_ROOT}" add -A`);
47+
const repoRoot = getRepoRoot();
48+
const result = await exec(`git -C "${repoRoot}" add -A`);
4349
return result.success;
4450
}
4551

4652
export async function stageFiles(files: string[]): Promise<boolean> {
4753
if (files.length === 0) return true;
54+
const repoRoot = getRepoRoot();
4855
const fileList = files.map((f) => `"${f}"`).join(" ");
49-
const result = await exec(`git -C "${REPO_ROOT}" add ${fileList}`);
56+
const result = await exec(`git -C "${repoRoot}" add ${fileList}`);
5057
return result.success;
5158
}
5259

5360
export async function commit(message: string): Promise<boolean> {
54-
const result = await exec(`git -C "${REPO_ROOT}" commit -m "${message}"`);
61+
const repoRoot = getRepoRoot();
62+
const result = await exec(`git -C "${repoRoot}" commit -m "${message}"`);
5563
return result.success;
5664
}
5765

5866
export async function push(): Promise<{ success: boolean; message: string }> {
59-
const result = await exec(`git -C "${REPO_ROOT}" push`);
67+
const repoRoot = getRepoRoot();
68+
const result = await exec(`git -C "${repoRoot}" push`);
6069
if (result.success) {
6170
return { success: true, message: "Pushed to remote" };
6271
}
6372
return { success: false, message: result.stderr || "Push failed" };
6473
}
6574

6675
export async function getCurrentBranch(): Promise<string> {
67-
const result = await exec(`git -C "${REPO_ROOT}" branch --show-current`);
76+
const repoRoot = getRepoRoot();
77+
const result = await exec(`git -C "${repoRoot}" branch --show-current`);
6878
return result.stdout || "unknown";
6979
}
7080

7181
export async function getRemoteUrl(): Promise<string | null> {
72-
const result = await exec(`git -C "${REPO_ROOT}" remote get-url origin`);
82+
const repoRoot = getRepoRoot();
83+
const result = await exec(`git -C "${repoRoot}" remote get-url origin`);
7384
return result.success ? result.stdout : null;
7485
}
7586

7687
export async function getDiff(file?: string): Promise<string> {
88+
const repoRoot = getRepoRoot();
7789
const fileArg = file ? ` -- "${file}"` : "";
78-
const result = await exec(`git -C "${REPO_ROOT}" diff${fileArg}`);
90+
const result = await exec(`git -C "${repoRoot}" diff${fileArg}`);
7991
return result.stdout;
8092
}
8193

8294
export async function getDiffCached(file?: string): Promise<string> {
95+
const repoRoot = getRepoRoot();
8396
const fileArg = file ? ` -- "${file}"` : "";
84-
const result = await exec(`git -C "${REPO_ROOT}" diff --cached${fileArg}`);
97+
const result = await exec(`git -C "${repoRoot}" diff --cached${fileArg}`);
8598
return result.stdout;
8699
}

0 commit comments

Comments
 (0)