Conversation
There was a problem hiding this comment.
Pull Request Overview
Optimize the algorithm for determining base branches by parsing the output of git show-branch and refactoring getBaseBranches to use the new parser.
- Introduces parseBaseBranchName(showBranch) to extract base branch names from git show-branch output.
- Refactors getBaseBranches to delegate to parseBaseBranchName.
- Adds unit tests covering multiple parse scenarios.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/gitremote.js | Adds parseBaseBranchName and updates getBaseBranches to use it. |
| test/gitopen.test.js | Adds tests for parseBaseBranchName with multiple scenarios. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| const m = RE_CURRENT_BRANCH.exec(info[0]); | ||
| // 输入异常,没有找到当前分支。 | ||
| if (!m) { | ||
| return ''; |
There was a problem hiding this comment.
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 []; |
| return brs | ||
| .map(br => { | ||
| var RE_BASE_BRANCHE_NAME = /^[ *+-]*\[([^\]\^~]+)/; // " +* [MS170216105211~2^2] test: fixed lint" |
There was a problem hiding this comment.
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 => { |
| * @return {Array} base branch name | ||
| */ | ||
| exports.parseBaseBranchName = function(showBranch) { | ||
| // 上下上个部分使用 -- 分隔。 |
There was a problem hiding this comment.
Correct the grammar and clarify the separator to match the actual code which splits on lines of hyphens.
| // 上下上个部分使用 -- 分隔。 | |
| // 上下部分使用只包含连字符的行(如 --、--- 等)分隔。 |
| /** | ||
| * 解析 `git show-branch` 的输出,得到当前分支的基准分支。 | ||
| * @param {String} showBranch 当前分支 `git show-branch` 的输出。 | ||
| * @return {Array} base branch name |
There was a problem hiding this comment.
The return description should be plural to reflect that an array of names is returned. Suggest: @return {Array} base branch names.
| * @return {Array} base branch name | |
| * @return {Array<string>} base branch names |
No description provided.