@panoptic-it-solutions/coolify-setup 1.1.26 → 1.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/git.js +107 -27
  2. package/package.json +1 -1
package/dist/git.js CHANGED
@@ -45,7 +45,11 @@ export async function commitAndPushToDevelop(files, originalBranch) {
45
45
  run('git init');
46
46
  }
47
47
  // Use passed-in branch name, or detect current branch
48
- const sourceBranch = originalBranch || run('git branch --show-current');
48
+ let sourceBranch = originalBranch || run('git branch --show-current');
49
+ // Handle detached HEAD state
50
+ if (!sourceBranch) {
51
+ sourceBranch = 'develop';
52
+ }
49
53
  // Stage all specified files (use -A to also stage deletions)
50
54
  for (const file of files) {
51
55
  try {
@@ -108,22 +112,63 @@ export async function commitAndPushToDevelop(files, originalBranch) {
108
112
  catch {
109
113
  // develop doesn't exist locally
110
114
  }
111
- if (developExistsLocally) {
112
- run('git checkout develop');
113
- }
114
- else {
115
- run('git checkout -b develop origin/develop');
116
- }
117
- // Pull latest changes
115
+ // Try to checkout develop
116
+ let checkoutSucceeded = false;
118
117
  try {
119
- run('git pull --rebase origin develop');
118
+ if (developExistsLocally) {
119
+ run('git checkout develop');
120
+ }
121
+ else {
122
+ run('git checkout -b develop origin/develop');
123
+ }
124
+ checkoutSucceeded = true;
120
125
  }
121
126
  catch {
122
- // Pull might fail, continue
127
+ // Checkout failed - might be worktree issue
128
+ // Try fast-forward push if source branch contains all develop commits
129
+ try {
130
+ run(`git merge-base --is-ancestor origin/develop ${sourceBranch}`);
131
+ // Source branch is ahead of develop, can fast-forward push
132
+ run(`git push origin ${sourceBranch}:develop`);
133
+ result.pushed = true;
134
+ return result;
135
+ }
136
+ catch {
137
+ // Can't fast-forward - develop has diverged, need real merge
138
+ throw new Error('Cannot checkout develop (may be used by another worktree) and branches have diverged. Please merge manually.');
139
+ }
140
+ }
141
+ if (checkoutSucceeded) {
142
+ // Pull latest changes
143
+ try {
144
+ run('git pull --rebase origin develop');
145
+ }
146
+ catch {
147
+ // Pull might fail, continue
148
+ }
149
+ // Merge the source branch (which has the commits)
150
+ try {
151
+ run(`git merge ${sourceBranch} --no-edit`);
152
+ }
153
+ catch {
154
+ // Merge conflict - abort and report
155
+ try {
156
+ run('git merge --abort');
157
+ }
158
+ catch {
159
+ // Abort might fail, continue
160
+ }
161
+ throw new Error(`Merge conflict between develop and ${sourceBranch}. Please resolve manually.`);
162
+ }
163
+ run('git push origin develop');
164
+ // Return to original branch
165
+ try {
166
+ run(`git checkout ${sourceBranch}`);
167
+ }
168
+ catch {
169
+ // Might fail if worktree, that's ok - user is on develop
170
+ }
123
171
  }
124
- // Merge the source branch (which has the commits)
125
- run(`git merge ${sourceBranch} --no-edit`);
126
- run('git push origin develop');
127
172
  }
128
173
  else {
129
174
  // Develop doesn't exist remotely, create it from source branch
@@ -193,27 +238,62 @@ export async function setupGitHub(projectName) {
193
238
  }
194
239
  // Ensure we're on develop branch and push to it
195
240
  try {
196
- const currentBranch = run('git branch --show-current');
241
+ const currentBranch = run('git branch --show-current') || 'develop';
197
242
  if (currentBranch !== 'develop') {
198
- // Check if develop exists locally
243
+ // Try to checkout develop
244
+ let checkoutSucceeded = false;
199
245
  try {
200
- run('git checkout develop');
246
+ // Check if develop exists locally
247
+ try {
248
+ run('git rev-parse --verify develop');
249
+ run('git checkout develop');
250
+ }
251
+ catch {
252
+ // Create develop from current branch
253
+ run('git checkout -b develop');
254
+ }
255
+ checkoutSucceeded = true;
201
256
  }
202
257
  catch {
203
- // Create develop from current branch
204
- run('git checkout -b develop');
258
+ // Checkout failed - might be worktree issue
259
+ // Try to push current branch to develop instead
260
+ try {
261
+ run(`git push origin ${currentBranch}:develop -u`);
262
+ result.developBranchCreated = true;
263
+ result.repoPushed = true;
264
+ // Skip the rest of develop push logic since we already pushed
265
+ checkoutSucceeded = false;
266
+ }
267
+ catch {
268
+ result.warnings.push('Failed to push develop branch (checkout failed, possibly worktree conflict)');
269
+ checkoutSucceeded = false;
270
+ }
271
+ }
272
+ if (checkoutSucceeded) {
273
+ // Pull latest changes before pushing to avoid non-fast-forward errors
274
+ try {
275
+ run('git pull --rebase origin develop');
276
+ }
277
+ catch {
278
+ // Pull might fail if remote doesn't exist yet, that's ok
279
+ }
280
+ run('git push origin develop -u');
281
+ result.developBranchCreated = true;
282
+ result.repoPushed = true;
205
283
  }
206
284
  }
207
- // Pull latest changes before pushing to avoid non-fast-forward errors
208
- try {
209
- run('git pull --rebase origin develop');
210
- }
211
- catch {
212
- // Pull might fail if remote doesn't exist yet, that's ok
285
+ else {
286
+ // Already on develop
287
+ try {
288
+ run('git pull --rebase origin develop');
289
+ }
290
+ catch {
291
+ // Pull might fail if remote doesn't exist yet, that's ok
292
+ }
293
+ run('git push origin develop -u');
294
+ result.developBranchCreated = true;
295
+ result.repoPushed = true;
213
296
  }
214
- run('git push origin develop -u');
215
- result.developBranchCreated = true;
216
- result.repoPushed = true;
217
297
  }
218
298
  catch {
219
299
  result.warnings.push('Failed to push develop branch');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panoptic-it-solutions/coolify-setup",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "description": "CLI tool for setting up Coolify deployment on Panoptic projects",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",