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

remote.origin.fetch is limited to the default branch #664

Open
zedtux opened this issue Apr 5, 2023 · 1 comment
Open

remote.origin.fetch is limited to the default branch #664

zedtux opened this issue Apr 5, 2023 · 1 comment

Comments

@zedtux
Copy link

zedtux commented Apr 5, 2023

Subject of the issue

Given I clone a git repository using git on my local machine, so without this lib, the remote.origin.fetch targets +refs/heads/*:refs/remotes/origin/* while when I clone the same repo but with this lib the the remote.origin.fetch targets +refs/heads/master:refs/remotes/origin/master.

This makes the fetch method not being able to retrieve other branches references and therefore the reset_hard method to fail with:

fatal: ambiguous argument 'origin/8-missing-reference-language-translation-files-in-yml': unknown revision or path not in the working tree.

Your environment

  • version of git: 2.32.6
  • version of ruby-git: 1.18.0
  • version of ruby: 2.7.6

Steps to reproduce

git = Git.clone(URL, destination)

# Supposed to retrieve all the remote branch refs, but is not
git.remote(Git::GIT_REMOTE_NAME).fetch

# Switches to the desired branch
git.branch('8-missing-reference-language-translation-files-in-yml').checkout

# Here we want to be fully aligned with the remote branch
git.reset_hard("#{Git::GIT_REMOTE_NAME}/8-missing-reference-language-translation-files-in-yml")
#=> fatal: ambiguous argument 'origin/8-missing-reference-language-translation-files-in-yml': unknown revision or path not in the working tree.

Expected behaviour

The remote.origin.fetch should be changed from:

remote.origin.fetch=+refs/heads/master:refs/remotes/origin/master

to:

remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*

Actual behaviour

See "Steps to reproduce"

@zedtux zedtux changed the title remote.origin.fetch is limited to the default branch remote.origin.fetch is limited to the default branch Apr 5, 2023
@zedtux
Copy link
Author

zedtux commented Apr 5, 2023

It appears this is a behaviour comes from git itself when passing the --depth flag.

One way to solve this is to call the git remote set-branches origin '*' as explain in this SO but this library doesn't seem to support it.
The alternative way of doing this is to update the .git/config file manually as described in the this issue.

For now, I will stop using the --depth flag. It would be nice to have that set-branches supported by this library 👍

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

No branches or pull requests

1 participant