Skip to content
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

Fix nix-prefetch-git for syntax variations. #570

Closed
wants to merge 3 commits into from

Conversation

kquick
Copy link
Contributor

@kquick kquick commented Jun 30, 2018

[Note: this pull request is suggested as a more comprehensive solution than https://github.com//pull/552
and also resolves https://github.com//issues/482 which is probably still an issue as well as https://github.com//issues/543 although not in the manner suggested therein.]

This fixes several issues for nix-prefetch-git:

  1. Variances in git submodule status output.

    Here are some examples of various output from this command:
    -20007c90b9c5e49c241df0494077f44d4559af45 submodules/foo
    20007c90b9c5e49c241df0494077f44d4559af45 submodules/foo (remotes/origin/stable-3-g20007c9)
    20007c90b9c5e49c241df0494077f44d4559af45 submodules/foo ((null))

    The original regex processing would only match the first of these.
    The observable effect of the other forms of output was complaints
    about "too many parameters to 'cd'" because the entire line was
    used as the "dir" and "hash" variable values.

  2. Remote URL determination.

    The original form attempted to parse the directory from the
    git submodule status output above and look that up in the
    .git/config file to determine the URL. Unfortunately, the
    latter file uses the config-ini section name as the index,
    as does the .gitmodules file, so if the section name differs
    from the subdirectory, this failed and returned a blank URL.

    Sample (valid!) .gitmodule contents that would exhibit
    this error:

    .gitmodules:
    [submodule "x86/tests/submodules/dwarf"]
    path = deps/dwarf
    url = https://github.com/myteam/dwarf.git

This patch resolves both of the above by using the the builtin
git submodule foreach to iterate through the submodules, where
this command explicitly sets shell variables to represent most
of the items, and the submodule lookup in .git/config is now done
using the submodule name and not the submodule path.

This fixes several issues for nix-prefetch-git:
1. Variances in `git submodule status` output.

   Here are some examples of various output from this command:
     -20007c90b9c5e49c241df0494077f44d4559af45 submodules/foo
      20007c90b9c5e49c241df0494077f44d4559af45 submodules/foo (remotes/origin/stable-3-g20007c9)
      20007c90b9c5e49c241df0494077f44d4559af45 submodules/foo ((null))

   The original regex processing would only match the first of these.
   The observable effect of the other forms of output was complaints
   about "too many parameters to 'cd'" because the entire line was
   used as the "dir" and "hash" variable values.

2. Remote URL determination.

   The original form attempted to parse the directory from the
   `git submodule status` output above and look that up in the
   .git/config file to determine the URL.  Unfortunately, the
   latter file uses the config-ini *section name* as the index,
   as does the .gitmodules file, so if the section name differs
   from the subdirectory, this failed and returned a blank URL.

   Sample (valid!) .gitmodule contents that would exhibit
   this error:

      .gitmodules:
      [submodule "x86/tests/submodules/dwarf"]
        path = deps/dwarf
        url = https://github.com/myteam/dwarf.git

This patch resolves both of the above by using the the builtin
`git submodule foreach` to iterate through the submodules, where
this command explicitly sets shell variables to represent most
of the items, and the submodule lookup in .git/config is now done
using the submodule name and not the submodule path.
@jokogr
Copy link

jokogr commented Jul 16, 2018

@kquick thanks for your PR, it works as expected!

@ElvishJerricco
Copy link

This did not work for me. I ended up with:

hydra-eval-jobs returned exit code 1:
error: getting status of '/nix/store/zgfw99j53sjq7m0kknsqakm26gkqmv4g-source/nixpkgs/default.nix': No such file or directory

nixpkgs is the submodule in my project

@kquick
Copy link
Contributor Author

kquick commented Jul 27, 2018

@ElvishJerricco is your top-level repo public such that I could reproduce this locally? Or if not, can you provide a minimal example that reproduces the issue?

[Sorry for the delay in responding to your feedback: I just returned from vacation.]

@jokogr
Copy link

jokogr commented Aug 28, 2018

Hmm, actually it did not work for me, too.

@kquick have a look @ https://hydra.microlab.ntua.gr/jobset/joko-nixos/unstable-boxen#tabs-configuration

The error:

hydra-eval-jobs returned exit code 1:
error: getting status of '/nix/store/bzzkv3iw918cma65y088rj7q14gixcrq-git-export/modules/systemd-zfs-generator/default.nix': No such file or directory
(use '--show-trace' to show detailed location information)

@kquick
Copy link
Contributor Author

kquick commented Aug 29, 2018

Thanks for the info @jokogr. I think I see the issue and will update this patch today or tomorrow when I get this resolved.

@kquick
Copy link
Contributor Author

kquick commented Aug 31, 2018

@jokogr @ElvishJerricco The latest version just uses the standard git functionality, which should be more reliable and addresses the issues you two reported. Thank you!


clone "$dir" "$url" "$hash" "";
done;
git submodule update --recursive

Choose a reason for hiding this comment

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

You could even fold this into the above line:

git submodule update --init --recursive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could, although I think the two specific steps provide more readability into the sequence of operations being performed. Your suggestion is definitely valid git but I always feel like the init is a command and it's being hidden behind an option flag when doing it that way. That's purely a stylistic perspective though: if I'm missing a technical reason why there's a difference I could easily be convinced to change my thinking here.

@aycanirican
Copy link
Member

Can we close this? Since it's already implemented in 8bffbb7

@ocharles
Copy link

That commit doesn't pass --recursive and I think it should.

@RaitoBezarius
Copy link
Member

Are you guys still interested into merging this PR?

@kquick
Copy link
Contributor Author

kquick commented Jan 24, 2020

@RaitoBezarius yes, I think this is an improvement and should be merged. The 8bffbb7 change includes an extra command that doesn't assist the process, and leaves in a misleading comment in addition to lacking the --recursive specification. The --recursive checkout cannot hurt anything (other than a bit of extra git checkout time) is a no-op for all of the non-recursive configurations (the majority) and there's currently no other mechanism where a git source requiring recursive submodules would be supported.

@RaitoBezarius
Copy link
Member

Can we do something to help @kquick ?

@kquick
Copy link
Contributor Author

kquick commented Apr 16, 2022

I submitted the PR and tried to keep it up to date for a while, but it appears there has been no interest by the maintainers in merging it. I'm not sure there's anything else to be done at this point other than closing it.

@kquick kquick closed this Apr 16, 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.

None yet

7 participants