@saeed42/worktree-worker 1.3.3 → 1.3.4
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/dist/main.js +40 -17
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -635,10 +635,26 @@ var RepoService = class {
|
|
|
635
635
|
`Repository already initialized with different URL. Current: ${currentUrl}, Requested: ${requestedUrl}. Use force=true to re-initialize (this will delete all worktrees).`
|
|
636
636
|
);
|
|
637
637
|
}
|
|
638
|
-
log.warn("Force re-init:
|
|
638
|
+
log.warn("Force re-init: clearing contents and cloning fresh");
|
|
639
639
|
await this.cleanAllWorktrees();
|
|
640
|
-
const
|
|
641
|
-
|
|
640
|
+
const targetBranch = options.branch || env.DEFAULT_BRANCH;
|
|
641
|
+
try {
|
|
642
|
+
const items = await readdir(repoRoot);
|
|
643
|
+
for (const item of items) {
|
|
644
|
+
const itemPath = `${repoRoot}/${item}`;
|
|
645
|
+
await rm(itemPath, { recursive: true, force: true });
|
|
646
|
+
}
|
|
647
|
+
log.info("Cleared directory contents", { repoRoot, itemsRemoved: items.length });
|
|
648
|
+
} catch (clearError) {
|
|
649
|
+
log.error("Failed to clear directory contents", { error: clearError });
|
|
650
|
+
throw new AppError("Failed to clear directory contents", "GIT_ERROR", clearError);
|
|
651
|
+
}
|
|
652
|
+
log.info("Cloning repository fresh", { branch: targetBranch });
|
|
653
|
+
await gitService.cloneRepo(options.repoUrl, repoRoot, {
|
|
654
|
+
branch: targetBranch,
|
|
655
|
+
blobless: true,
|
|
656
|
+
githubToken: options.githubToken
|
|
657
|
+
});
|
|
642
658
|
await gitService.exec(["config", "--local", "user.name", "origin-agent[bot]"], repoRoot);
|
|
643
659
|
await gitService.exec([
|
|
644
660
|
"config",
|
|
@@ -647,14 +663,9 @@ var RepoService = class {
|
|
|
647
663
|
"origin-agent[bot]@users.noreply.github.com"
|
|
648
664
|
], repoRoot);
|
|
649
665
|
await gitService.exec(["config", "--local", "safe.directory", repoRoot], repoRoot);
|
|
650
|
-
const
|
|
651
|
-
|
|
666
|
+
const cleanUrl = options.repoUrl.replace(/^https:\/\/[^@]+@/, "https://");
|
|
667
|
+
await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
|
|
652
668
|
await gitService.fetch("origin", repoRoot, auth);
|
|
653
|
-
try {
|
|
654
|
-
await gitService.exec(["checkout", "-B", targetBranch, `origin/${targetBranch}`, "--force"], repoRoot);
|
|
655
|
-
} catch {
|
|
656
|
-
await gitService.exec(["checkout", "-B", targetBranch, "--force"], repoRoot);
|
|
657
|
-
}
|
|
658
669
|
await gitService.exec(["branch", `--set-upstream-to=origin/${targetBranch}`, targetBranch], repoRoot).catch(
|
|
659
670
|
() => {
|
|
660
671
|
}
|
|
@@ -662,7 +673,7 @@ var RepoService = class {
|
|
|
662
673
|
const headSha2 = await gitService.getHeadSha(repoRoot);
|
|
663
674
|
const branch2 = await gitService.getCurrentBranch(repoRoot);
|
|
664
675
|
const remote2 = await gitService.getRemoteUrl("origin", repoRoot);
|
|
665
|
-
log.info("Repository
|
|
676
|
+
log.info("Repository cloned fresh", { branch: branch2, headSha: headSha2 });
|
|
666
677
|
return { path: repoRoot, branch: branch2, headSha: headSha2, remote: remote2 };
|
|
667
678
|
}
|
|
668
679
|
const parentDir = repoRoot.split("/").slice(0, -1).join("/");
|
|
@@ -671,8 +682,23 @@ var RepoService = class {
|
|
|
671
682
|
const dirExists = await stat2(repoRoot).then(() => true).catch(() => false);
|
|
672
683
|
const branch = options.branch || env.DEFAULT_BRANCH;
|
|
673
684
|
if (dirExists) {
|
|
674
|
-
log.info("Directory exists,
|
|
675
|
-
|
|
685
|
+
log.info("Directory exists, clearing contents and cloning fresh", { branch });
|
|
686
|
+
try {
|
|
687
|
+
const items = await readdir(repoRoot);
|
|
688
|
+
for (const item of items) {
|
|
689
|
+
const itemPath = `${repoRoot}/${item}`;
|
|
690
|
+
await rm(itemPath, { recursive: true, force: true });
|
|
691
|
+
}
|
|
692
|
+
log.info("Cleared directory contents", { repoRoot, itemsRemoved: items.length });
|
|
693
|
+
} catch (clearError) {
|
|
694
|
+
log.error("Failed to clear directory contents", { error: clearError });
|
|
695
|
+
throw new AppError("Failed to clear directory contents", "GIT_ERROR", clearError);
|
|
696
|
+
}
|
|
697
|
+
await gitService.cloneRepo(options.repoUrl, repoRoot, {
|
|
698
|
+
branch,
|
|
699
|
+
blobless: true,
|
|
700
|
+
githubToken: options.githubToken
|
|
701
|
+
});
|
|
676
702
|
await gitService.exec(["config", "--local", "user.name", "origin-agent[bot]"], repoRoot);
|
|
677
703
|
await gitService.exec([
|
|
678
704
|
"config",
|
|
@@ -682,11 +708,8 @@ var RepoService = class {
|
|
|
682
708
|
], repoRoot);
|
|
683
709
|
await gitService.exec(["config", "--local", "safe.directory", repoRoot], repoRoot);
|
|
684
710
|
const cleanUrl = options.repoUrl.replace(/^https:\/\/[^@]+@/, "https://");
|
|
685
|
-
await gitService.exec(["remote", "
|
|
686
|
-
await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
|
|
687
|
-
});
|
|
711
|
+
await gitService.exec(["remote", "set-url", "origin", cleanUrl], repoRoot);
|
|
688
712
|
await gitService.fetch("origin", repoRoot, auth);
|
|
689
|
-
await gitService.exec(["checkout", "-B", branch, `origin/${branch}`, "--force"], repoRoot);
|
|
690
713
|
await gitService.exec(["branch", `--set-upstream-to=origin/${branch}`, branch], repoRoot).catch(
|
|
691
714
|
() => {
|
|
692
715
|
}
|