-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor xgit upload defaults to preserve history; add --message/--force controls
#6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
7
commits into
master
Choose a base branch
from
copilot/override-existing-files-keep-history
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−12
Draft
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5db543
Update upload defaults and add message/force options
Copilot dfb9cd4
Address review feedback on upload parameter style and branch order
Copilot 1361643
Simplify upload message option forwarding
Copilot 1bd2f05
Refine upload option parsing without type assertions
Copilot b957b11
Flatten upload force branch to reduce indentation
Copilot 2a7229b
Merge non-force upload branches with default target folder
Copilot 988c347
Move force upload branch below common path
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,40 +74,52 @@ async function uploadFolder( | |
| sourceFolder: string, | ||
| GitURL: string, | ||
| targetBranch: string, | ||
| targetFolder?: string | ||
| targetFolder?: string, | ||
| { message = 'upload by Git-utility CLI', force = false } = {} | ||
| ) { | ||
| sourceFolder = path.resolve(sourceFolder); | ||
|
|
||
| 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}`; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 保留原有的分支顺序,以便减少 Git 差异。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 已按原有顶层分支顺序调整为 |
||
| } | ||
|
|
||
| Command.execute( | ||
|
|
@@ -135,13 +147,30 @@ Command.execute( | |
| name="upload" | ||
| parameters="<sourceFolder> <GitURL> <targetBranch> [targetFolder]" | ||
| description="Upload a folder to a Git repository" | ||
| options={{ | ||
| message: { | ||
| shortcut: 'm', | ||
| parameters: '<message>', | ||
| description: 'Custom commit message' | ||
| }, | ||
| force: { | ||
| shortcut: 'f', | ||
| description: | ||
| 'Discard Git history and force-push source folder' | ||
| } | ||
| }} | ||
| executor={( | ||
| _, | ||
| { message, force }, | ||
| sourceFolder: string, | ||
| GitURL: string, | ||
| targetBranch: string, | ||
| targetFolder?: string | ||
| ) => uploadFolder(sourceFolder, GitURL, targetBranch, targetFolder)} | ||
| ) => | ||
| uploadFolder(sourceFolder, GitURL, targetBranch, targetFolder, { | ||
| message: typeof message === 'string' ? message : undefined, | ||
| force: force === true | ||
| }) | ||
| } | ||
| /> | ||
| <Command name="submodule" description="Manage Git submodules"> | ||
| <Command | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用普通参数形式
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改为普通参数形式,
uploadFolder现在使用message、force常规参数,不再用对象解构。已在提交dfb9cd4中处理。CLI 变更无 UI,截图不适用。