This repository was archived by the owner on May 3, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
1414 unstageAllFiles ,
1515 getName ,
1616 getEmail ,
17+ setupUpstreamBranch ,
1718} from './utils/git' ;
1819import {
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}
Original file line number Diff line number Diff line change @@ -21,7 +21,18 @@ export function isInGitRepo(): boolean {
2121}
2222
2323export 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
2738export function addAllChanges ( ) : void {
You can’t perform that action at this time.
0 commit comments