@jhorst11/wt 1.0.0 → 1.0.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jhorst11/wt",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "🌳 Beautiful interactive git worktree manager",
5
5
  "type": "module",
6
6
  "bin": {
package/src/commands.js CHANGED
@@ -320,6 +320,8 @@ export async function createWorktreeFlow() {
320
320
  success(`Created worktree at ${colors.path(result.path)}`);
321
321
  if (result.branchCreated) {
322
322
  success(`Created new branch ${colors.branch(branchName)}`);
323
+ } else if (result.branchSource === 'updated-from-remote') {
324
+ info(`Updated branch ${colors.branch(branchName)} to match remote`);
323
325
  } else {
324
326
  info(`Using existing branch ${colors.branch(branchName)} (${result.branchSource})`);
325
327
  }
package/src/git.js CHANGED
@@ -213,12 +213,34 @@ export async function branchExistsRemote(branchName, cwd = process.cwd()) {
213
213
  export async function ensureBranch(branchName, baseBranch = null, cwd = process.cwd()) {
214
214
  const git = await getGit(cwd);
215
215
 
216
+ // If baseBranch is a remote ref, fetch it first to ensure it's up to date
217
+ if (baseBranch && baseBranch.startsWith('origin/')) {
218
+ const remoteBranchName = baseBranch.replace('origin/', '');
219
+ await git.fetch(['origin', `${remoteBranchName}:refs/remotes/origin/${remoteBranchName}`]).catch(() => {});
220
+ }
221
+
216
222
  // Check if branch exists locally
217
223
  if (await branchExistsLocal(branchName, cwd)) {
224
+ // If we have a remote baseBranch, update local branch to match it
225
+ if (baseBranch && baseBranch.startsWith('origin/')) {
226
+ try {
227
+ const localSha = (await git.revparse([branchName])).trim();
228
+ const remoteSha = (await git.revparse([baseBranch])).trim();
229
+
230
+ if (localSha !== remoteSha) {
231
+ // Local branch exists but points to different commit than remote
232
+ // Reset the local branch to match the remote
233
+ await git.branch(['-f', branchName, baseBranch]);
234
+ return { created: false, source: 'updated-from-remote' };
235
+ }
236
+ } catch {
237
+ // If we can't compare, fall through to use local as-is
238
+ }
239
+ }
218
240
  return { created: false, source: 'local' };
219
241
  }
220
242
 
221
- // Check if branch exists on remote
243
+ // Check if branch exists on remote (with same name as branchName)
222
244
  if (await branchExistsRemote(branchName, cwd)) {
223
245
  await git.fetch(['origin', `${branchName}:${branchName}`]);
224
246
  return { created: false, source: 'remote' };
@@ -226,11 +248,6 @@ export async function ensureBranch(branchName, baseBranch = null, cwd = process.
226
248
 
227
249
  // Create new branch from base
228
250
  if (baseBranch) {
229
- // If baseBranch is remote, make sure we have it locally
230
- if (baseBranch.startsWith('origin/')) {
231
- const localName = baseBranch.replace('origin/', '');
232
- await git.fetch(['origin', localName]).catch(() => {});
233
- }
234
251
  await git.branch([branchName, baseBranch]);
235
252
  } else {
236
253
  await git.branch([branchName]);