Skip to content

Current_git: ensure stale submodules are removed#345

Merged
tmcgilchrist merged 3 commits intoocurrent:masterfrom
talex5:fix-submodules
May 8, 2022
Merged

Current_git: ensure stale submodules are removed#345
tmcgilchrist merged 3 commits intoocurrent:masterfrom
talex5:fix-submodules

Conversation

@talex5
Copy link
Copy Markdown
Contributor

@talex5 talex5 commented May 4, 2022

  • Do git submodule deinit first, otherwise git won't remove old files on reset.
  • Add a test for this.

I also removed the extra submodule update and sync added recently. The sync only affects initialised submodules and there aren't any with this change. The extra update was to help the sync succeed.

Fixes #340.

@talex5 talex5 requested a review from dra27 May 4, 2022 13:35
@MisterDA
Copy link
Copy Markdown
Contributor

MisterDA commented May 4, 2022

What if we keep the old code and also do git clean -ffdx? I agree that git deinit seems cleaner (and easier to understand) but maybe it's not as efficient cache-wise?

@talex5
Copy link
Copy Markdown
Contributor Author

talex5 commented May 4, 2022

I don't think deinit affects the caching:

after deinitializing the Git directory is kept around
(https://git-scm.com/docs/gitsubmodules)

@MisterDA
Copy link
Copy Markdown
Contributor

MisterDA commented May 4, 2022

I don't think deinit affects the caching:

after deinitializing the Git directory is kept around
(https://git-scm.com/docs/gitsubmodules)

I missed that, thanks.
And many more thanks for figuring out how to fix this!

@dra27
Copy link
Copy Markdown
Contributor

dra27 commented May 4, 2022

Thanks for grasping this one! Does it still fix the original problem which is where the submodule URL changes?

@dra27
Copy link
Copy Markdown
Contributor

dra27 commented May 4, 2022

It’s the scenario described in #320 (comment) - I think from my experiments, git submodule deinit followed by a re-init/update still caused the wrong URL in the submodule’s git repo

talex5 added 2 commits May 5, 2022 10:54
- Do `git submodule deinit` first, otherwise git won't remove old files on reset.
- Add a test for this.

I also removed the extra submodule update and sync added recently. The
sync only affects initialised submodules and there aren't any with this
change. The extra update was to help the sync succeed.
Calling `deinit` prevents `sync` from working.
We now also fetch the submodules in the `fetch` step, not in the
checkout.
@talex5 talex5 force-pushed the fix-submodules branch from 0957893 to ada5243 Compare May 5, 2022 09:54
@talex5
Copy link
Copy Markdown
Contributor Author

talex5 commented May 5, 2022

I think from my experiments, git submodule deinit followed by a re-init/update still caused the wrong URL in the submodule’s git repo

Ah, you're right! If you deinit a submodule and then reinit it, it reuses the address from before the deinit instead of reinitialising it. How annoying.

I've added a second commit with a test for moving a submodule's repository and made some fixes for it. We now also fetch submodules during the fetch step, not when checking out (which might help with caching too).

This reverts commit ef24ca3, which
causes checkouts to fail with e.g.

    error: pathspec 'refs/pull/449/head' did not match any file(s) known to git
@talex5
Copy link
Copy Markdown
Contributor Author

talex5 commented May 5, 2022

I also reverted "Checkout to the correct branch in with_checkout" from #333, since it prevents building PRs and therefore makes testing this difficult.

@dra27
Copy link
Copy Markdown
Contributor

dra27 commented May 5, 2022

I'm not sure that this Dockerfile is exactly what's happening now, but it demonstrates what I think is still the problem:

FROM ocaml/opam AS base
RUN git clone https://github.com/ocurrent/ocluster.git --recursive
WORKDIR ocluster

FROM base
RUN sed -i -e s/ocurrent/dra27/ .gitmodules
RUN git submodule sync
RUN grep 'url = .*/obuilder\.git' * .git* -rI

FROM base
RUN rm -rf *
RUN git reset --hard HEAD
RUN sed -i -e s/ocurrent/dra27/ .gitmodules
RUN git submodule sync
RUN git submodule deinit --all --force
RUN git submodule update --init --recursive
RUN grep 'url = .*/obuilder\.git' * .git* -rI

In the first run, with the checkout as normal, we see:

.git/config:    url = https://github.com/dra27/obuilder.git
.git/modules/obuilder/config:   url = https://github.com/dra27/obuilder.git
.gitmodules:    url = https://github.com/dra27/obuilder.git

the second run attempts to simulate the default state of an OCurrent .git cache - which should be just a .git directory (because that's what we'd copied). At which point we have:

.git/config:    url = https://github.com/dra27/obuilder.git
.git/modules/obuilder/config:   url = https://github.com/ocurrent/obuilder.git
.gitmodules:    url = https://github.com/dra27/obuilder.git

git submodule update before the reset fixes it (which was the temporary fix). Another - possibly better - fix is to copy the .git directory _and any other .git files in the tree (so in the example, if obuilder/.git is restored after the rm -rf then the three URLs are also correctly updated).

@talex5
Copy link
Copy Markdown
Contributor Author

talex5 commented May 5, 2022

The URLs shouldn't matter in the checkout (after copying .git) because we're not doing any fetching at that point now (enforced with ~fetch:false):

Cmd.git_submodule_update ~init:true ~cancellable:true ~fetch:false ~job ~repo:tmpdir

@dra27
Copy link
Copy Markdown
Contributor

dra27 commented May 5, 2022

Oh, I get it, now, thanks!

@tmcgilchrist tmcgilchrist merged commit 06f66d3 into ocurrent:master May 8, 2022
tmcgilchrist added a commit to tmcgilchrist/opam-repository that referenced this pull request Jun 2, 2022
…, current_github, current_git, current_examples, current_docker and current (0.6.1)

CHANGES:

Web UI:

- UI restyle, embed files using ocaml-crunch. (@ewanmellor, @MisterDA, ocurrent/ocurrent#315)

- Automatically refresh some pipeline pages. (@MisterDA, ocurrent/ocurrent#227)

- Allow to import and export using CSV the log rules. (@MisterDA, ocurrent/ocurrent#327)

- Log matcher takes the pattern with the highest score (@kit-ty-kate, ocurrent/ocurrent#335)

API:

- GitHub: Add pp_short for commit and fix url link for GH commits. (@tmcgilchrist, ocurrent/ocurrent#347)

- GitHub: Fetch commit messages for commits on GitHub (@punchagan, ocurrent/ocurrent#337)

- GitHub: Add Current_github.Api.cmdliner_opt. (@dra27, ocurrent/ocurrent#338)

- GitHub: Add extra PR information to Ref.t (@tmcgilchrist @TheLortex, ocurrent/ocurrent#336)

Plugins:

- GitLab: support GitLab clone fork and fetch MR branch. (@MisterDA, ocurrent/ocurrent#346)

- Git: Fix handling of git repositories with submodules. (@talex5, ocurrent/ocurrent#345)

- GitLab: Fix ref filtering bug for GitLab (@tmcgilchrist, ocurrent/ocurrent#332)

Other:

- Add missing dependencies on Unix (@dra27, ocurrent/ocurrent#331)
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.

Stale submodules not removed

4 participants