Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

export content of git submodules #1909

Closed
wants to merge 7 commits into from

Conversation

pohly
Copy link

@pohly pohly commented Jun 25, 2018

What does this do / why do we need it?

The "git checkout-index" command is unaware of git submodules,
therefore their content was missed when exporting files. Only a few projects have submodules (for example, git-hooks in github.com/nightlyone/lockfile and idl in github.com/uber/jaeger-client-go) and it seems that so far those submodules were not needed.

But nonetheless, the extra files are part of the source tree and thus should be exported because some projects might depend on them.

What should your reviewer look out for in this PR?

The tests for this feature depend on repos that I created under github.com/pohly. I can keep them there, but it might be cleaner to clone them into your own org and then update the tests.

@pohly pohly requested a review from jmank88 as a code owner June 25, 2018 14:36
@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

1 similar comment
@googlebot
Copy link
Collaborator

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@pohly
Copy link
Author

pohly commented Jun 28, 2018

Please note that I should be covered by a company CLA between Intel and Google. Let me know if you need more details to find that CLA.

@sdboyer
Copy link
Member

sdboyer commented Jul 2, 2018

Wow. Who'dve thought there'd be yet another reason i'd hate git submodules.

If you could provide a bit more info on the Intel<>Google CLA, that'd be helpful - being that i'm not a Google employee, i don't have ready access to that information, and i'd rather not trip over anything here.

Does the usage of POSIX shell syntax work also on Mac OS and Windows?

On OSX, yes. i'm not sure about Windows. That tests pass on appveyor suggests it's probably fine, but if you can think of any way to test this reasonably easily, it would be helpful.

Also, a CHANGELOG entry, please!

@pohly
Copy link
Author

pohly commented Jul 3, 2018 via email

@pohly pohly force-pushed the export-git-submodule branch from 078c630 to 2b9f10f Compare July 6, 2018 16:17
@sdboyer sdboyer added this to the v0.5.0 milestone Jul 11, 2018
@pohly pohly force-pushed the export-git-submodule branch from 2b9f10f to e7d68db Compare July 23, 2018 19:13
@pohly pohly requested a review from ibrasho as a code owner July 23, 2018 19:13
@pohly
Copy link
Author

pohly commented Jul 23, 2018

@sdboyer I've rebased and added a testcase with recursive submodules. I don't think there were any test cases which had a submodule at all. The new test revealed that my original code only worked for exporting submodules from the main repo - it failed for submodules inside submodules.

In order to test this, I had to extend the integration testing a bit. Otherwise it would not have detected the missing submodule files. The new testing should now confirm whether the code also works on non-Linux platforms.

Regarding the CLA: I'm still working on it :-/ In the meantime consider this a RFC patch, and not a contribution - it cannot be merged yet.

@pohly pohly changed the title export content of git submodules RFC: export content of git submodules - not a contribution (yet) Jul 23, 2018
@pohly
Copy link
Author

pohly commented Jul 23, 2018

About the test: the new repos are under github.com/pohly and I can keep them there in perpetuity, but it might be better to move them to github.com/sdboyer so that they are under your control. You don't need a CLA for that, do you?

@pohly pohly force-pushed the export-git-submodule branch 2 times, most recently from 541c402 to 2230db0 Compare July 23, 2018 20:23
@pohly
Copy link
Author

pohly commented Jul 23, 2018

Hmm, it failed on appvoyer once (https://ci.appveyor.com/project/golang/dep/build/3389) but after I changed the appvoyer config to be more verbose it succeeded without any other changes.

@sdboyer sdboyer removed this from the v0.5.0 milestone Jul 23, 2018
@sdboyer
Copy link
Member

sdboyer commented Jul 23, 2018

Cool - i'll aim to have a look at this next week, as this week is focused on shipping v0.5.0.

@pohly
Copy link
Author

pohly commented Jul 31, 2018

I signed it!

This is for the CLA bot - I should be on the approved contributor list now.

@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@googlebot googlebot removed the cla: no label Jul 31, 2018
@googlebot
Copy link
Collaborator

CLAs look good, thanks!

@pohly pohly force-pushed the export-git-submodule branch from 2230db0 to 996d706 Compare July 31, 2018 14:35
@pohly pohly changed the title RFC: export content of git submodules - not a contribution (yet) export content of git submodules Jul 31, 2018
When running "internal" and "external" versions of the same test case
in parallel, the test case data must be read-only to avoid race
conditions. When it is read/write because the tests were asked to
update the reference files with "-update", running in parallel must be
disabled.

This broke in practice when updating entire directory trees. The risk
of hitting the race is smaller when only updating single files, but it
is still a race.
Debugging a failing test with dlv is possible, but in contrast to "go
test", "dlv test" doesn't change the current working directory, which
is necessary for the test to find its test data.
@pohly
Copy link
Author

pohly commented Oct 29, 2018

@sdboyer I understand that your priorities may have shifted now, but as I depend on "dep" and go modules don't look like a viable alternative it would be nice to get this merged.

// "<root>/foo" for bar. By stripping our root
// directory we get a relative path that we can
// append to the target directory.
"(cd $(grep gitdir .git | sed -e 's;gitdir: *;;' .git) && mv index origindex && trap 'mv origindex index' EXIT && git read-tree \"$sha1\" && git checkout-index -a --prefix=\""+to+"$(echo \"$toplevel\" | sed -e 's;"+r.LocalPath()+";;')/$path/\")",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grep, sed, etc., - not gonna be portable to windows 😢

Let's take an approach with two execs - call out to git to enumerate the submodules, loop over the results with a call to fs.RenameWithFallback(), then call out again with git submodule foreach. Simplicity, correctness and portability are worth the performance hit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What command should be used to enumerate the submodules?

If it's "git submodule foreach", then I still have the same problem: what can I put into that script that is portable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should be able to get what you need from git submodule status output. Icky, but it's there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, you mentioned before (#1909 (comment)) that the shell code might be okay because "tests pass on appveyor suggests it's probably fine". That was before I added an explicit test for submodules, but it continued to pass also after I added the new testcase. So just to be sure, automatic testing in appveyor includes running dep on Windows?

But I've rewritten the code such that it is based on the output of git submodule status anyway, with the "export tree" functionality done by the same Go code as before, just moved to a new method. It's easier to understand this way. The only thing I don't like about it is parsing the output of git submodule status, because there is no well-defined, machine-readable output format.


// CopyTree recursively copies a source directory into a target directory.
// Target directories are created if they don't exist yet.
func CopyTree(dest, src string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't have something like this already?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how hard I searched for it. It's possible that I just overlooked such an utility function. If so, can your provide a pointer?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've got CopyDir -

func CopyDir(src, dst string) error {

i think that should do it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this CopyTree wasn't something that I created ;-) I just moved it here from testproj.go. But replacing it with CopyDir still sounds like a good idea.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a separate commit which removes this code duplication.

This PR is starting to collect some commits which could also be merged separately, like that cleanup commit. Please let me know whether I should create separate PRs for that or whether you are fine with merging everything in one go.

@pohly pohly force-pushed the export-git-submodule branch from 996d706 to 3a2fadb Compare January 3, 2019 15:48
pohly added 5 commits January 3, 2019 17:07
The functionality is the same and some minor differences (target
directory must not exist when using fs.CopyDir) can be handled by
being careful about creating the temporary directories.
So far, only the list of vendored projects and the top-level
Gopk.toml/lock files were compared. This way it was impossible to
write integration tests that also check the content of the vendored
projects.

Now a test case can specify that it's 'final' directory contains a
complete set of reference files, and then all files are checked
respectively updated (when --updated is given). Directories and file
meta still aren't checked.

The reference files of existing tests can be changed on a case-by-case
basis. This new comparison mode cannot be enabled unconditionally
because a few tests then fail because each test run creates
_vendor-<datetime> directories which are named differently in each
test run.
The "git checkout-index" command is unaware of git submodules,
therefore their content was missed when exporting files.

With "git submodule foreach" the same operation (read-tree +
checkout-index) can also be done for all submodules, recursively. The
downside is that "foreach" invokes a shell command with certain
variables set. To achieve the desired functionality, we have to rely
on POSIX shell support.

OTOH, the command seems to get embedded by git in a larger shell
script because error messages when there are syntax errors show that the
command gets invoked via `eval`, so git already depends on a POSIX
shell.
This new test fails if the content of two recursive submodules is not
exported. Verification depends on comparing the entire "final"
directory.
Without the logs it is impossible to understand why certain commands
fail.
@pohly pohly force-pushed the export-git-submodule branch from 3a2fadb to 8447e4c Compare January 3, 2019 16:07
@pohly
Copy link
Author

pohly commented Jan 3, 2019

@sdboyer please have another look. There are test failures, but they seem unrelated to this PR.

@mvdan
Copy link
Member

mvdan commented Sep 4, 2020

Dep was officially deprecated earlier this year, and the proposal to archive this repository was accepted. As such, I'm closing outstanding issues before archiving the repository. For any further comments, please use the proposal thread on the Go issue tracker. Thanks!

@mvdan mvdan closed this Sep 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants