-
Notifications
You must be signed in to change notification settings - Fork 974
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
Checkout submodules error if the previous update of submodules was interrupted #12806
Comments
Based on those error messages, this looks like you are using a plugin material, not a built-in material for GoCD. The fix for this would have to be with the relevant plugin, not in GoCD (although GoCD may have a similar issue, would have to check). Which plugin material are you using? |
We use this: https://github.com/ashwanthkumar/gocd-build-github-pull-requests The error falls into the plugin, however, as far as I can tell, the problem is not in it, but in the reset algorithm: I ran these commands in the git console, outside of the GoCD, and still got an error in the Here are the steps to reproduce the situation in the console:
Perhaps this case is more visual when there are a lot of submodules, in my project about 40, the update takes time. During this time, it may fall, and I have to fix it manually every time. |
The clean + reset algorithm is the responsibility of the plugin. While GoCD "proper" might have had the same problem, the plugin is responsible for everything on the material including prepping it, resetting etc and the error indicates the problem is in the plugin right now. Similar to https://groups.google.com/g/go-cd/c/tfaenMirnLs the problem needs to be fixed there. In GoCD core Git materials, I believe this issue was fixed in #5964 by switching to Likely a similar thing needs to be done on the plugin, which uses this "reusable" library code for git interactions: Since the intent is for it to work similarly to GoCD itself, it could be changed to a similar default behaviour as GoCD itself, even relying upon the same system property "opt out". gocd/domain/src/main/java/com/thoughtworks/go/domain/materials/git/GitCommand.java Lines 453 to 460 in 67fbd63
|
Hiya - have you checked this out empirically? I can create PRs to the library and the plugin it uses to align with GoCD out-of-the-box semantics, but only Ashwanth can release the library to Maven and a new version, which is what it sounds like it needs to address your problem if |
What's the If this is the only possible fix, you should be aware that I am pretty nervous about changing the logic here, or otherwise changing the semantics of anything core within the git material. I don't have deep experience with git submodules (which I personally consider a pretty painful and unreliable feature to work with) and there aren't many other folks to help validate or give input. It would seem to have some capacity to break things, and I am not entirely sure it's the "right way" to fix it, as it would seem to impose a tax on all material updates, even for submodules in the normal state, rather than doing something to perhaps avoid leaving them broken in the first place. |
This is I understand your concerns about this case, so it would be great if you (or maybe someone else) could reproduce it. Submodules are really not that popular, a project with a lot of submodules is a fairly rare thing, I think this is the reason why I caught it now. About the proposed fix: one of the existing commands is
|
Yeah, I understand and somewhat share the mode of thinking here, however the hard reset is necessary for the top level material to get to the specific target revision that GoCD is tracking. In the submodule case the revisions need to follow that implies by the parent repository, not anything GoCD is tracking, so it’s not necessarily true that they need to be hard reset to get there - theoretically the submodule update should be enough to get there. it’s possibly just an accident that the hard reset on the parent happens to clean up any broken updates on the parent? |
You're right, and in valid situations, updating the submodule should be enough. However, as you can see, errors happen. This creates a local diff, and until the state of the submodule has not been reset, the following operations cannot be performed with them, including updating. I don't really know how to catch an exception in this case, so clearing the submodules looks quite logical to me. I've been thinking about a solution now, and it might be safer to use
|
Yeah, I don't disagree - just nitpicking on "the original motivation for hard reset" being the same between parent and subs. They are different, so not necessarily true to need to apply the same mechanism to the subs. No big deal though.
Worth noting in #5856 (comment) that Worth thinking about and determining which is "safer" and which is "faster". My instinct is that the hard reset is probably faster with fewer file writes to the local working copy, but if we can consolidate the commands to what reasonably modern Git can be expected to support, it might be the best of all worlds. ... and then there is Current GoCD does all manner of stuff for submodules that I don't really understand though (removing them from git config? doing checkout manually rather than The below was essentially introduced in 2009, for example: 😅
gocd/domain/src/main/java/com/thoughtworks/go/domain/materials/git/GitCommand.java Lines 544 to 555 in 67fbd63
This joyous code also dates from March 2009:
At one point in 2012 it did do an There was also some back and forth in #5856 with some submodule stuff reverted in #6024. Some of that "support old git" stuff can definitely be removed now, if we have confidence there is a better/safer/easier way. You can probably get an idea why I am a bit nervous to go too deep though. There are a lot of scenarios to validate, and requires some time to see how many of these the automated tests cover. |
Yes, you're right, if take into account the speed and support of older versions of git, then the hard reset looks better. The main advantage of deinit is working whatever the state of submodules, it seemed to me that this is more reliable, but in the case of a large number of submodules, the difference in processing time will probably be very unpleasant.
Talking about
About removing from git config - it caches submodules data there (active flag, url), and if submodule url changed without removing from config step - we have invalid data. Unfortunately, it doesn't pull it up automatically.
There is another idea - it is not so easy to implement, but it will solve this problem. Would it be possible to make a preprepare script to add custom commands before preparing the material? Perhaps this will give more flexibility to users. |
Yeah, to be clear, I am OK dropping support for old git versions. GoCD doesn't have the engineering input/capacity to care about this type of stuff (ancient git), so as long as it supports the versions that are available on standard repos for the oldest LTS linux distros we have container images for (Debian 11, RHEL 8, Ubuntu 20) it's fine to me. Which I think basically means Git |
I'd rather not do this. Some operations need to be performed on the server, and some on the agent. These have different needs, and as soon as you give control to the user you have all manners of "broken" that a repo or its working copy could be in before GoCD touches it. That's a support nightmare and it'd make it actively harder to implement things GoCD really should support (but does not right now), such as partial clones. |
It seems rather odd to me that that command could give |
Hey, I have not come up with new solutions, but I made a test repo with 30 submodules, you can use it. It's just a random data inside. https://github.com/AlenaKarp/submodules_owner.git I reproduced the bug on it, there is the state of the repository after an interrupted update in the archive. If possible, please try it too. test_submodules_invalid.zip |
Issue Type
Summary
There is a repository with submodules. Each time switching between branches, the git is reset and the submodules are updated. In case of interruption of the update process, all the following build processes crash at the stage of checking out submodules, because the repository is in an invalid state.
Basic environment details
Steps to Reproduce
This error is repeated in all jobs that run further, until you manually reset the submodules.
Expected Results
Submodules are reset automatically.
Actual Results
Error when trying to checkout submodules.
Possible Fix
Add reset submodules step when reset working directory.
The text was updated successfully, but these errors were encountered: