-
Notifications
You must be signed in to change notification settings - Fork 993
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
[bug] Git.checkout() with a target folder doesn't work with the remaining Git functions #14058
Comments
Hi @fschoenm Thanks for your report. The def source(self):
git = Git(self)
target = os.path.join(self.source_folder, "target")
git.clone(url="{url}", target=target)
git.folder = target
git.checkout(commit="{commit}")
```
I'd say this is not a bug, but intended. I will submit a PR to propose to make this automatic, but probably hiding the detail is not that great, and having explicit the fact that the current folder for "git" commands has changed is better, lets see what the team thinks. |
Actually, I didn't really understand why there are two folders involved, a target folder and a working directory, and what is their relationship. Do you mean it might work to just set the folder and all commands (including |
The folder that is defined is the For the use case at and, it is also possible (and probably what makes sense) to do: def source(self):
git = Git(self, "target")
git.clone(url="{url}", target=".")
git.checkout(commit="{commit}") Note the |
Closed by the test in #14063. git = Git(self)
git.clone(url="{url}", target="target") # git clone url target
git.folder = "target" # cd target
git.checkout(commit="{commit}") # git checkout commit |
@memsharded Sorry but I don't really understand the use case. The multiple directories are kind of confusing and I think if I want to only clone and checkout a commit, I shouldn't have to handle two directories. How does that even work with your imaginary use case of having multiple clones from the same The only use case that seems straight forward is having |
If you want to clone and checkout a commit you do have to handle 2 directories:
The
It is not imaginary. I said it clearly git = Git(self)
git.clone(url="{url-sources}", target="sources") # git clone url-sources sources
git.clone(url="{url-scripts}", target="scripts") # git clone url-scripts scripts
git.folder = "sources" # cd sources
git.checkout(commit="{commit-sources}") # git checkout commit-sources
git.folder = "scripts" # cd ../scripts
git.checkout(commit="{commit-scripts}") # git checkout commit-scripts I find this nicely explicit, easy to read and understand (anyone reading this code can understand the intention) and completely straightforward. If the expectation is that |
@memsharded Sorry if that came off wrong, I didn't meant "imaginary" but "hypothetical". I don't doubt those use cases exist (and it would be easily handled by having multiple I also can see how your example would be very straight forward, it just isn't very abstract. In the end, what's the point of having a helper class that doesn't abstract (almost) anything away? I could just call I just wish Conan would have more high-level helper objects for handling such common use cases but in my recent experiments with Conan 2.x I have the feeling, it is developing in the opposite direction. Things like the |
Environment details
Steps to reproduce
The
conan.tools.scm.Git
interface seems lacking. If I specify atarget
folder in theclone()
command, there seems to be no straight-forward way to correctly use the otherGit
functions likecheckout()
. They're all going to be executed in the wrong directory.Logs
Giving this error:
The text was updated successfully, but these errors were encountered: