-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: 优化获取基准分支的算法。 #82
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -93,29 +93,57 @@ exports.getRemoteBranches = function(cwd) { | |||||||||||||
| return remoteBranches; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| var RE_CURRENT_BASE_BRANCHES = /^[ -+]*\*/; | ||||||||||||||
| var RE_BASE_BRANCHE_NAME = /.*?\[([^\]\^~]+).*/; // " +* [MS170216105211~2^2] test: fixed lint" | ||||||||||||||
| /** | ||||||||||||||
| * 解析 `git show-branch` 的输出,得到当前分支的基准分支。 | ||||||||||||||
| * @param {String} showBranch 当前分支 `git show-branch` 的输出。 | ||||||||||||||
| * @return {Array} base branch name | ||||||||||||||
| */ | ||||||||||||||
| exports.parseBaseBranchName = function(showBranch) { | ||||||||||||||
| // 上下上个部分使用 -- 分隔。 | ||||||||||||||
|
||||||||||||||
| // 上下上个部分使用 -- 分隔。 | |
| // 上下部分使用只包含连字符的行(如 --、--- 等)分隔。 |
Copilot
AI
Oct 17, 2025
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.
This returns a string when no current branch match is found, but the function’s JSDoc declares an Array and callers (e.g., getBaseBranches) will then receive a string. Return an empty array instead: return [];.
| return ''; | |
| return []; |
Copilot
AI
Oct 17, 2025
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.
The regular expression is recompiled for every line inside map, which is unnecessary. Hoist it outside the loop and use const, e.g., const RE_BASE_BRANCH_NAME = /^[ +-]\[([^\\]\^~]+)/; then reuse it inside map.
| return brs | |
| .map(br => { | |
| var RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint" | |
| const RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint" | |
| return brs | |
| .map(br => { |
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.
The return description should be plural to reflect that an array of names is returned. Suggest: @return {Array} base branch names.