| 1165 | } |
| 1166 | |
| 1167 | async push(credentialsId?: string | null, force = false) { |
| 1168 | console.log(`[git] Push remote=origin force=${force ? 'true' : 'false'}`); |
| 1169 | |
| 1170 | const response = await git.push({ |
| 1171 | ...this._baseOpts, |
| 1172 | ...gitCallbacks(credentialsId), |
| 1173 | remote: 'origin', |
| 1174 | force, |
| 1175 | }); |
| 1176 | |
| 1177 | if (response.error) { |
| 1178 | console.log('[git] Push rejected', response); |
| 1179 | throw new Error( |
| 1180 | `Push rejected with errors: ${response.error}.\n\nGo to View > Toggle DevTools > Console for more information.`, |
| 1181 | ); |
| 1182 | } |
| 1183 | |
| 1184 | if ('errors' in response && response.errors && Array.isArray(response.errors)) { |
| 1185 | console.log('[git] Push failed with errors', response.errors); |
| 1186 | const errorsString = JSON.stringify(response.errors); |
| 1187 | throw new Error( |
| 1188 | `Push rejected with errors: ${errorsString}.\n\nGo to View > Toggle DevTools > Console for more information.`, |
| 1189 | ); |
| 1190 | } |
| 1191 | |
| 1192 | // NOTE: Response can be ok and have errors so we check this in the end to make sure we throw an error if there are any. |
| 1193 | if (response.ok) { |
| 1194 | console.log('[git] Push successful'); |
| 1195 | return; |
| 1196 | } |
| 1197 | |
| 1198 | throw new Error('Push failed with unknown error. Please try again.'); |
| 1199 | } |
| 1200 | |
| 1201 | async hasUncommittedChanges() { |
| 1202 | const changes = await this.status(); |