@@ -442,9 +442,10 @@ export const GithubRunCommand = cmd({
442442 const head = ( await $ `git rev-parse HEAD` ) . stdout . toString ( ) . trim ( )
443443 const dataPrompt = buildPromptDataForPR ( prData )
444444 const response = await chat ( `${ userPrompt } \n\n${ dataPrompt } ` , promptFiles )
445- if ( await branchIsDirty ( head ) ) {
445+ const { dirty, uncommittedChanges } = await branchIsDirty ( head )
446+ if ( dirty ) {
446447 const summary = await summarize ( response )
447- await pushToLocalBranch ( summary )
448+ await pushToLocalBranch ( summary , uncommittedChanges )
448449 }
449450 const hasShared = prData . comments . nodes . some ( ( c ) => c . body . includes ( `${ shareBaseUrl } /s/${ shareId } ` ) )
450451 await updateComment ( `${ response } ${ footer ( { image : ! hasShared } ) } ` )
@@ -455,9 +456,10 @@ export const GithubRunCommand = cmd({
455456 const head = ( await $ `git rev-parse HEAD` ) . stdout . toString ( ) . trim ( )
456457 const dataPrompt = buildPromptDataForPR ( prData )
457458 const response = await chat ( `${ userPrompt } \n\n${ dataPrompt } ` , promptFiles )
458- if ( await branchIsDirty ( head ) ) {
459+ const { dirty, uncommittedChanges } = await branchIsDirty ( head )
460+ if ( dirty ) {
459461 const summary = await summarize ( response )
460- await pushToForkBranch ( summary , prData )
462+ await pushToForkBranch ( summary , prData , uncommittedChanges )
461463 }
462464 const hasShared = prData . comments . nodes . some ( ( c ) => c . body . includes ( `${ shareBaseUrl } /s/${ shareId } ` ) )
463465 await updateComment ( `${ response } ${ footer ( { image : ! hasShared } ) } ` )
@@ -470,9 +472,10 @@ export const GithubRunCommand = cmd({
470472 const issueData = await fetchIssue ( )
471473 const dataPrompt = buildPromptDataForIssue ( issueData )
472474 const response = await chat ( `${ userPrompt } \n\n${ dataPrompt } ` , promptFiles )
473- if ( await branchIsDirty ( head ) ) {
475+ const { dirty, uncommittedChanges } = await branchIsDirty ( head )
476+ if ( dirty ) {
474477 const summary = await summarize ( response )
475- await pushToNewBranch ( summary , branch )
478+ await pushToNewBranch ( summary , branch , uncommittedChanges )
476479 const pr = await createPR (
477480 repoData . data . default_branch ,
478481 branch ,
@@ -805,43 +808,57 @@ export const GithubRunCommand = cmd({
805808 return `opencode/${ type } ${ issueId } -${ timestamp } `
806809 }
807810
808- async function pushToNewBranch ( summary : string , branch : string ) {
811+ async function pushToNewBranch ( summary : string , branch : string , commit : boolean ) {
809812 console . log ( "Pushing to new branch..." )
810- await $ `git add .`
811- await $ `git commit -m "${ summary }
813+ if ( commit ) {
814+ await $ `git add .`
815+ await $ `git commit -m "${ summary }
812816
813817Co-authored-by: ${ actor } <${ actor } @users.noreply.github.com>"`
818+ }
814819 await $ `git push -u origin ${ branch } `
815820 }
816821
817- async function pushToLocalBranch ( summary : string ) {
822+ async function pushToLocalBranch ( summary : string , commit : boolean ) {
818823 console . log ( "Pushing to local branch..." )
819- await $ `git add .`
820- await $ `git commit -m "${ summary }
824+ if ( commit ) {
825+ await $ `git add .`
826+ await $ `git commit -m "${ summary }
821827
822828Co-authored-by: ${ actor } <${ actor } @users.noreply.github.com>"`
829+ }
823830 await $ `git push`
824831 }
825832
826- async function pushToForkBranch ( summary : string , pr : GitHubPullRequest ) {
833+ async function pushToForkBranch ( summary : string , pr : GitHubPullRequest , commit : boolean ) {
827834 console . log ( "Pushing to fork branch..." )
828835
829836 const remoteBranch = pr . headRefName
830837
831- await $ `git add .`
832- await $ `git commit -m "${ summary }
838+ if ( commit ) {
839+ await $ `git add .`
840+ await $ `git commit -m "${ summary }
833841
834842Co-authored-by: ${ actor } <${ actor } @users.noreply.github.com>"`
843+ }
835844 await $ `git push fork HEAD:${ remoteBranch } `
836845 }
837846
838847 async function branchIsDirty ( originalHead : string ) {
839848 console . log ( "Checking if branch is dirty..." )
840849 const ret = await $ `git status --porcelain`
841850 const status = ret . stdout . toString ( ) . trim ( )
842- if ( status . length > 0 ) return true
851+ if ( status . length > 0 ) {
852+ return {
853+ dirty : true ,
854+ uncommittedChanges : true ,
855+ }
856+ }
843857 const head = await $ `git rev-parse HEAD`
844- return head . stdout . toString ( ) . trim ( ) !== originalHead
858+ return {
859+ dirty : head . stdout . toString ( ) . trim ( ) !== originalHead ,
860+ uncommittedChanges : false ,
861+ }
845862 }
846863
847864 async function assertPermissions ( ) {
0 commit comments