[QA-390] Clean stale submodules when mode=full, method=copy#4
Merged
kax-slamcore merged 1 commit intoslamcore_releasefrom Nov 22, 2022
Merged
Conversation
This change calls `git clean` appropriately for the checked-out repository and any submodules when checking out or switching branches. Motivation: Consider the case where a submodule exists on branch-a but not branch-b. When using `mode=full` and `method=copy`, a `source` directory will exist and it will contain the repository at branch-a. If the next build is for branch-b, the following commands will be executed: 1. git fetch -f -t <source> branch-b --progress 2. git reset --hard <tip of branch-b> -- 3. git checkout -B branch-b 4. git submodule sync 5. git submodule update --init --recursive --force --checkout Command 2 here is expected to reset the checkout to the state <tip of branch-b>, however it will fail to remove the submodule directory and will issue a warning like: ``` warning: unable to rmdir 'path/to/submodule': Directory not empty ``` This leaves the source directory in an unexpected state and may cause errors in the build. Implementation: This change ensures that `git clean -f -f -d -x` is called on the checkout and that `_cleanSubmodule()` is called to clean submodules recursively also. Note that `-f` is required twice as: > Git will refuse to modify untracked nested git repositories (directories > with a .git subdirectory) unless a second -f is given. -- man git-clean Alternatives: Initially, the option to `git submodule deinit --all` before resetting the state was considered but this would require re-cloning submodules in the more common case where they exist on both the current and previous build.
nikoskoukis-slamcore
approved these changes
Nov 22, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change calls
git cleanappropriately for the checked-out repository and any submodules when checking out or switching branches.Motivation:
Consider the case where a submodule exists on branch-a but not branch-b. When using
mode=fullandmethod=copy, asourcedirectory will exist and it will contain the repository at branch-a. If the next build is for branch-b, the following commands will be executed:Command 2 here is expected to reset the checkout to the state , however it will fail to remove the submodule directory and will issue a warning like:
This leaves the source directory in an unexpected state and may cause errors in the build.
Implementation:
This change ensures that
git clean -f -f -d -xis called on the checkout and that_cleanSubmodule()is called to clean submodules recursively also.Note that
-fis required twice as:-- man git-clean
Alternatives:
Initially, the option to
git submodule deinit --allbefore resetting the state was considered but this would require re-cloning submodules in the more common case where they exist on both the current and previous build.Testing
Aside from the updated unit tests on this branch, I've also tested this as follows:
Setup
slamcore_ros2'smainbranch. This doesn't have to finish, just clone. -> http://kax-desktop.slamcore.local:8010/#/builders/78/builds/86Test
slamcore_ros2'srelease_v21.06branch.Current behaviour
Passing behaviour