Skip to content

Refactor xgit upload defaults to preserve history; add --message/--force controls#6

Draft
Copilot wants to merge 7 commits into
masterfrom
copilot/override-existing-files-keep-history
Draft

Refactor xgit upload defaults to preserve history; add --message/--force controls#6
Copilot wants to merge 7 commits into
masterfrom
copilot/override-existing-files-keep-history

Conversation

Copilot AI commented May 10, 2026

Copy link
Copy Markdown
Contributor
  • Inspect latest actionable PR comment and current uploadFolder implementation
  • Re-run baseline validation commands
  • Reorder upload conditional branches to keep force branch below and minimize diff
  • Re-run validation after code change
  • Reply to new review comment with addressing commit hash

Comment thread src/index.tsx Outdated
targetBranch: string,
targetFolder?: string
targetFolder?: string,
{ message = 'upload by Git-utility CLI', force = false } = {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用普通参数形式

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改为普通参数形式,uploadFolder 现在使用 messageforce 常规参数,不再用对象解构。已在提交 dfb9cd4 中处理。CLI 变更无 UI,截图不适用。

Comment thread src/index.tsx Outdated
Comment on lines +81 to +122
if (targetFolder) {
const tempFolder = path.join(os.tmpdir(), new URL(GitURL).pathname);

await fs.remove(tempFolder);
await fs.mkdirp(tempFolder);
cd(tempFolder);

await $`git clone -b ${targetBranch} ${GitURL} .`;

targetFolder = path.join(tempFolder, targetFolder);

await fs.remove(targetFolder);
await fs.mkdirp(targetFolder);
await fs.copy(sourceFolder, targetFolder);
await fs.remove(path.join(targetFolder, '.git'));

await $`git add .`;
await $`git commit -m "upload by Git-utility CLI"`;
await $`git push origin ${targetBranch}`;
} else {
if (force) {
cd(sourceFolder);

await $`git init`;
await $`git remote add origin ${GitURL}`;
await $`git checkout -b ${targetBranch}`;
await $`git add .`;
await $`git commit -m "upload by Git-utility CLI"`;
await $`git commit -m ${message}`;
await $`git push --set-upstream origin ${targetBranch} -f`;
await fs.remove('.git');

return;
}

const tempFolder = path.join(os.tmpdir(), new URL(GitURL).pathname);

await fs.remove(tempFolder);
await fs.mkdirp(tempFolder);
cd(tempFolder);

await $`git clone -b ${targetBranch} ${GitURL} .`;

const uploadTarget = targetFolder
? path.join(tempFolder, targetFolder)
: tempFolder;

await fs.mkdirp(uploadTarget);

for (const entry of await fs.readdir(sourceFolder))
if (entry !== '.git')
await fs.copy(
path.join(sourceFolder, entry),
path.join(uploadTarget, entry),
{
overwrite: true
}
);

await $`git add .`;
await $`git commit -m ${message}`;
await $`git push origin ${targetBranch}`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

保留原有的分支顺序,以便减少 Git 差异。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按原有顶层分支顺序调整为 if (targetFolder) ... else ...,同时保留默认保留历史的新行为。已在提交 dfb9cd4 中处理。CLI 变更无 UI,截图不适用。

Copilot AI requested a review from TechQuery May 10, 2026 22:41
Comment thread src/index.tsx Outdated
Comment on lines +109 to +110
} else {
cd(sourceFolder);

await $`git init`;
await $`git remote add origin ${GitURL}`;
await $`git checkout -b ${targetBranch}`;
await $`git add .`;
await $`git commit -m "upload by Git-utility CLI"`;
await $`git push --set-upstream origin ${targetBranch} -f`;
await fs.remove('.git');
if (force) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else 和 if 合并,可以减少一层缩进,才能看得清差异。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已按建议把 else { if (...) ... } 合并为 else if (...),减少一层缩进,便于看差异。对应提交:b957b11。CLI 逻辑调整无 UI 变更,截图不适用。

Copilot AI requested a review from TechQuery May 10, 2026 23:44
Comment thread src/index.tsx Outdated
Comment on lines 119 to 141
} else {
const tempFolder = path.join(os.tmpdir(), new URL(GitURL).pathname);

await fs.remove(tempFolder);
await fs.mkdirp(tempFolder);
cd(tempFolder);

await $`git clone -b ${targetBranch} ${GitURL} .`;

for (const entry of await fs.readdir(sourceFolder))
if (entry !== '.git')
await fs.copy(
path.join(sourceFolder, entry),
path.join(tempFolder, entry),
{
overwrite: true
}
);

await $`git add .`;
await $`git commit -m ${message}`;
await $`git push origin ${targetBranch}`;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

targetFolder = '.' 的默认值,这个分支是不是就和最上面的分支能合并成一种?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理,统一了非 force 的上传分支:通过 targetFolder ||= '.' 让根目录上传与目标子目录上传走同一套 clone/overlay/push 逻辑;仅在“未传 targetFolder--force”时走强推分支。对应提交:2a7229b。CLI 逻辑调整无 UI 变更,截图不适用。

Copilot AI requested a review from TechQuery May 11, 2026 11:54
Comment thread src/index.tsx Outdated
Comment on lines +85 to +95
if (uploadToRoot && force) {
cd(sourceFolder);

await $`git init`;
await $`git remote add origin ${GitURL}`;
await $`git checkout -b ${targetBranch}`;
await $`git add .`;
await $`git commit -m ${message}`;
await $`git push --set-upstream origin ${targetBranch} -f`;
await fs.remove('.git');
} else {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把这个分支放到下面,还是那个原则 —— 把 Git 差异降到最低!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已调整为把该分支放到下面:先走通用上传路径,force 特例放到 else,以尽量贴近原始分支顺序并降低差异。对应提交:988c347。CLI 逻辑调整无 UI 变更,截图不适用。

Copilot AI requested a review from TechQuery May 11, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants