Repository navigation
Conversation
…xisting repo When switching branches in an existing git.repo, fetch the target branch from its tracking remote instead of hardcoded 'origin'. This fixes shallow clone fetches where the target branch is not available locally. Key changes: - Fetch the target branch from the tracking remote before checkout - Use the tracking remote for the current branch instead of 'origin' - Add --depth and --force flags to fetch for shallow clones - Add --tags flag when fetch_tags is enabled Co-authored-by: Junie <junie@jetbrains.com>
wowi42
left a comment
There was a problem hiding this comment.
The branch-switching fix is not ready yet. The shallow single-branch failure and remote selection issue are inline. Maintainer edits are also disabled on the fork.
| git_commands.append(StringCommand("fetch", *fetch_options, *force_flag_list)) | ||
| # Determine the remote tracking the current branch; fall back to | ||
| # "origin" if the config key is absent (e.g. detached HEAD). | ||
| tracking_remote = git_config.get(f"branch.{current_branch}.remote", ["origin"])[0] |
There was a problem hiding this comment.
git fetch origin mybranch does not create refs/remotes/origin/mybranch after a shallow single-branch clone, so the following checkout still fails. Please create or use a checkoutable ref and add a real shallow-clone regression test. Also, branch.<current_branch>.remote can select a repository unrelated to src, while the operation reconciles and checks origin. Please fetch the target from the intended source.
| tracking_remote = git_config.get(f"branch.{current_branch}.remote", ["origin"])[0] | ||
| git_commands.append( | ||
| StringCommand( | ||
| "fetch", *fetch_options, *force_flag_list, tracking_remote, QuoteString(branch) |
There was a problem hiding this comment.
tracking_remote is passed as a raw string to StringCommand. Repository config can therefore inject shell syntax. Please wrap it with QuoteString and add a quoting fixture.
When using shallow clones it is possible for git to skip fetching the correct branch data. This change attempts to implement the fix to enable that to succeed.
I'm not happy that the command now always tries to fetch from origin but don't know if thats an issue or not - I'd appreciate guidance on this one.
Closes #2088
3.xat this time)scripts/dev-test.sh)scripts/dev-lint.sh)