@@ -80,8 +80,15 @@ function generateWorktree(action, worktreedir, branchExists) {
80
80
catch ( error ) {
81
81
( 0 , core_1 . info ) ( 'Error encountered while checking out branch. Attempting to continue with a new branch name.' ) ;
82
82
branchName = `temp-${ Date . now ( ) } ` ;
83
- checkout = new GitCheckout ( branchName ) ;
84
- yield ( 0 , execute_1 . execute ) ( checkout . toString ( ) , `${ action . workspace } /${ worktreedir } ` , action . silent ) ;
83
+ try {
84
+ checkout = new GitCheckout ( branchName , `origin/${ action . branch } ` ) ;
85
+ yield ( 0 , execute_1 . execute ) ( checkout . toString ( ) , `${ action . workspace } /${ worktreedir } ` , action . silent ) ;
86
+ }
87
+ catch ( error ) {
88
+ ( 0 , core_1 . info ) ( 'Unable to track the origin branch…' ) ;
89
+ checkout = new GitCheckout ( branchName ) ;
90
+ yield ( 0 , execute_1 . execute ) ( checkout . toString ( ) , `${ action . workspace } /${ worktreedir } ` , action . silent ) ;
91
+ }
85
92
}
86
93
if ( ! branchExists ) {
87
94
( 0 , core_1 . info ) ( `Created the ${ branchName } branch… 🔧` ) ;
@@ -91,15 +98,15 @@ function generateWorktree(action, worktreedir, branchExists) {
91
98
// New history isn't singleCommit, create empty initial commit
92
99
yield ( 0 , execute_1 . execute ) ( `git commit --no-verify --allow-empty -m "Initial ${ branchName } commit"` , `${ action . workspace } /${ worktreedir } ` , action . silent ) ;
93
100
}
94
- /**
95
- * Ensure that the workspace is a safe directory.
96
- */
97
- try {
98
- yield ( 0 , execute_1 . execute ) ( `git config --global --add safe.directory " ${ action . workspace } / ${ worktreedir } "` , action . workspace , action . silent ) ;
99
- }
100
- catch ( _a ) {
101
- ( 0 , core_1 . info ) ( 'Unable to set worktree temp directory as a safe directory…' ) ;
102
- }
101
+ }
102
+ /**
103
+ * Ensure that the workspace is a safe directory.
104
+ */
105
+ try {
106
+ yield ( 0 , execute_1 . execute ) ( `git config --global --add safe.directory " ${ action . workspace } / ${ worktreedir } "` , action . workspace , action . silent ) ;
107
+ }
108
+ catch ( _a ) {
109
+ ( 0 , core_1 . info ) ( 'Unable to set worktree temp directory as a safe directory…' ) ;
103
110
}
104
111
}
105
112
catch ( error ) {
0 commit comments