Skip to content
This repository was archived by the owner on May 3, 2025. It is now read-only.

Commit edf219b

Browse files
authored
Push no remote (#23)
* feat: enhance push functionality with upstream branch setup --------- Co-authored-by: IanSkelskey <IanSkelskey@users.noreply.github.com>
1 parent 1e759e9 commit edf219b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
unstageAllFiles,
1515
getName,
1616
getEmail,
17+
setupUpstreamBranch,
1718
} from './utils/git';
1819
import {
1920
confirmCommitMessage,
@@ -132,7 +133,15 @@ async function executeCommitWorkflow(systemPrompt: string, diff: string) {
132133
print('success', 'Commit successful.');
133134

134135
if (options.push) {
135-
pushChanges();
136+
try {
137+
pushChanges();
138+
print('success', 'Push successful.');
139+
} catch (error: any) {
140+
if (error.message.includes('The current branch has no upstream branch.')) {
141+
setupUpstreamBranch();
142+
}
143+
}
144+
136145
print('success', 'Push successful.');
137146
}
138147
}

src/utils/git.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,18 @@ export function isInGitRepo(): boolean {
2121
}
2222

2323
export function pushChanges(): void {
24-
execSync('git push');
24+
try {
25+
execSync('git push');
26+
} catch (error: any) {
27+
if (error.message.includes('fatal: The current branch')) {
28+
throw new Error('The current branch has no upstream branch.');
29+
}
30+
}
31+
}
32+
33+
export function setupUpstreamBranch() {
34+
const branchName = getCurrentBranchName();
35+
execSync(`git push --set-upstream origin ${branchName}`);
2536
}
2637

2738
export function addAllChanges(): void {

0 commit comments

Comments
 (0)