Skip to content

[QA-390] Clean stale submodules when mode=full, method=copy#4

Merged
kax-slamcore merged 1 commit intoslamcore_releasefrom
QA-390-clean-up-stale-submodules
Nov 22, 2022
Merged

[QA-390] Clean stale submodules when mode=full, method=copy#4
kax-slamcore merged 1 commit intoslamcore_releasefrom
QA-390-clean-up-stale-submodules

Conversation

@kax-slamcore
Copy link
Copy Markdown

@kax-slamcore kax-slamcore commented Nov 21, 2022

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 branch-b --progress
  2. git reset --hard --
  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 , 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.

Testing

Aside from the updated unit tests on this branch, I've also tested this as follows:

Setup

  1. Deploy this version of buildbot
  2. Build slamcore_ros2's main branch. This doesn't have to finish, just clone. -> http://kax-desktop.slamcore.local:8010/#/builders/78/builds/86

Test

  1. Build slamcore_ros2's release_v21.06 branch.

Current behaviour

  1. The build fails with an error like http://buildbot.slamcore.local/#/builders/61/builds/713
[0.177s] ERROR:colcon:colcon build: Duplicate package names not supported:
- slamcore_slam:
  - src/slamcore_ros2_wrapper/slamcore_slam
  - src/slamcore_slam

Passing behaviour

  1. The branch should build without issue -> http://kax-desktop.slamcore.local:8010/#/builders/78/builds/87

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.
@kax-slamcore kax-slamcore changed the base branch from QA-347-sync-submodules-recursively to slamcore_release November 22, 2022 13:00
@kax-slamcore kax-slamcore merged commit 157d0b6 into slamcore_release Nov 22, 2022
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

Successfully merging this pull request may close these issues.

2 participants