Skip to content
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

SCM module does not checkout git branch if the repo already exists #1630

Open
abeverley opened this issue Jan 5, 2025 · 3 comments · May be fixed by #1631
Open

SCM module does not checkout git branch if the repo already exists #1630

abeverley opened this issue Jan 5, 2025 · 3 comments · May be fixed by #1631
Labels
bug Confirmed bugs

Comments

@abeverley
Copy link
Contributor

Describe the bug

When using checkout from Rex::Commands::SCM, if the repo already exists in the target dir, then a specified branch is not checked-out. E.g.

    checkout "my_repo",
        branch => 'other_branch',
        path   => 'target_dir';

If target_dir already exists then other_branch is not checked-out

Expected behavior

After running the above command, I expect git status to show it is on the other_branch branch.

How to reproduce it

  1. checkout "my_repo", branch => 'master', path => 'target_dir';
  2. checkout "my_repo", branch => 'other_branch', path => 'target_dir';

Code example

No response

Additional context

No response

Rex version

1.14.3

Perl version

5.34.0

Operating system running rex

Ubuntu 22.04

Operating system managed by rex

Debian

How rex was installed?

cpan client

@abeverley abeverley added the triage needed A potential bug that needs to be reproduced and understood label Jan 5, 2025
@abeverley
Copy link
Contributor Author

I am happy to sponsor this bug.

Looking at the code for Rex::SCM::Git the condition for is_dir("$checkout_to/.git") does not include the CHECKOUT_BRANCH_COMMAND command (although it does include switching to a tag) whereas the else code does include CHECKOUT_BRANCH_COMMAND.

@ferki ferki added bug Confirmed bugs and removed triage needed A potential bug that needs to be reproduced and understood labels Jan 8, 2025
@ferki
Copy link
Member

ferki commented Jan 8, 2025

Thanks for reporting, @abeverley, as well as kindly offering to sponsor working on this!

Based on a quick software archaeology study, original intent looks like “if the repo already exists, update it with git pull; if a branch is passed, pull the branch”.

That results in the correct commits on the wrong branch in the cloned repo. I agree this is confusing, and we probably can find a way to make the results both “more correct” and more consistent across use cases.

I still would like to take another deeper look to make sure we can do all that accidentally without breaking backwards compatibility. Even then, I currently still lean towards treating it as a bug, and fixing it properly, rather than preserving a confusing behavior.

The good news is that I already implemented initial tests for Rex::SCM::Git in t/scm/git.t, so we have some headstart to include additional cases about the expected branch checkout behavior.

@ferki
Copy link
Member

ferki commented Jan 8, 2025

As a workaround, checkout 'my_repo', tag => 'other_branch', path => 'target_dir'; may work, even if using tag instead of branch just replaces one confusion with another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants