[Nix#3701] fetchGit can't handle annotated tags #152

Open
opened 2024-03-19 01:01:31 +00:00 by lix-bot · 1 comment
Member

Upstream-Issue: NixOS/nix#3701

Description

Currently builtins.fetchGit does not seem to handle annotated tags and fails with:

error: cannot update ref 'refs/heads/xyz': trying to write non-commit object 098abc123 to branch 'refs/heads/xyz'

Reproduction

You can see me reproduce this in https://github.com/status-im/status-react/issues/10825.

Docs

This was reported once in #2385 and a fix for docs was applied in ae244af242 by adding:

Due to a bug #2385 only non-annotated tags can be fetched.

To documentation of builtins.fetchGit, but that change does not seem to be there in current docs:
https://nixos.org/nix/manual/#ssec-builtins
And there doesn't appear to be any fix in sight.

Solutions

If the fix is difficult to implement for builtins.fetchGit could we at least update the documentation with this information and make fetchGit return an error that actually makes sense instead of this trying to write non-commit object nonsense?

Upstream-Issue: https://git.lix.systems/NixOS/nix/issues/3701 ## Description Currently `builtins.fetchGit` does not seem to handle annotated tags and fails with: ``` error: cannot update ref 'refs/heads/xyz': trying to write non-commit object 098abc123 to branch 'refs/heads/xyz' ``` ## Reproduction You can see me reproduce this in https://github.com/status-im/status-react/issues/10825. ## Docs This was reported once in #2385 and a fix for docs was applied in ae244af242ca3621e5a3b9196f27d9fcbf297266 by adding: >Due to a bug #2385 only non-annotated tags can be fetched. To documentation of `builtins.fetchGit`, but that change does not seem to be there in current docs: https://nixos.org/nix/manual/#ssec-builtins And there doesn't appear to be any fix in sight. ## Solutions If the fix is difficult to implement for `builtins.fetchGit` could we at least update the documentation with this information and make `fetchGit` return an error that actually makes sense instead of this `trying to write non-commit object` nonsense?
lix-bot added the
bug
imported
labels 2024-03-19 01:01:31 +00:00
Owner

It seems to be more complex than this. On Lix and Nix 2.18 alike, builtins.fetchGit fails to fetch any tag unless it's prefixed with refs/tags/, but if can fetch annotated tags if they are prefixed. In Nix 2.3 however, builtins.fetchGit can fetch unannotated tags unprefixed, but annotated tags need refs/tags/.

Lix:

Lix 2.90.0-lixpre20240511-a30c567

nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; }
fatal: couldn't find remote ref refs/heads/v2.0.3-status
error:
        while calling the 'fetchGit' builtin
         at «string»:1:1:
            1| builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; }
             | ^

        while fetching the input 'git+https://github.com/tbenr/react-native-audio-toolkit?ref=v2.0.3-status'

       error: program 'git' failed with exit code 128

nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "refs/tags/v2.0.3-status"; }
{
  lastModified = 1592064236;
  lastModifiedDate = "20200613160356";
  narHash = "sha256-VLUvxb9xRpMjkfASt4d4UMjnL0HlLb8ZEQKrk4RFZn4=";
  outPath = "/nix/store/idsax8hnzcn3pv56x2gmqr5mvy5564xb-source";
  rev = "53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f";
  revCount = 219;
  shortRev = "53e823d";
  submodules = false;
}

nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; }
fatal: couldn't find remote ref refs/heads/v0.2.5
error:
        while calling the 'fetchGit' builtin
         at «string»:1:1:
            1| builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; }
             | ^

        while fetching the input 'git+https://github.com/Qyriad/log2compdb?ref=v0.2.5'

       error: program 'git' failed with exit code 128

nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "refs/tags/v0.2.5"; }
{
  lastModified = 1693509864;
  lastModifiedDate = "20230831192424";
  narHash = "sha256-+olw0aMxsWbsmYvJEBAw2QCS6zPE7YyV46o2Vhn4VsY=";
  outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source";
  rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756";
  revCount = 38;
  shortRev = "b3a6989";
  submodules = false;
}

nix-repl>

2.18:

Welcome to Nix 2.18.2. Type :? for help.
nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; }
fatal: couldn't find remote ref refs/heads/v2.0.3-status
error:
        while calling the 'fetchGit' builtin

         at «string»:1:1:

            1| builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; }
             | ^

        while fetching the input 'git+https://github.com/tbenr/react-native-audio-toolkit?ref=v2.0.3-status'

       error: program 'git' failed with exit code 128

nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "refs/tags/v2.0.3-status"; }
{ lastModified = 1592064236; lastModifiedDate = "20200613160356"; narHash = "sha256-VLUvxb9xRpMjkfASt4d4UMjnL0HlLb8ZEQKrk4RFZn4="; outPath = "/nix/store/idsax8hnzcn3pv56x2gmqr5mvy5564xb-source"; rev = "53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f"; revCount = 219; shortRev = "53e823d"; submodules = false; }

nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; }
fatal: couldn't find remote ref refs/heads/v0.2.5
error:
        while calling the 'fetchGit' builtin

         at «string»:1:1:

            1| builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; }
             | ^

        while fetching the input 'git+https://github.com/Qyriad/log2compdb?ref=v0.2.5'

       error: program 'git' failed with exit code 128

nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "refs/tags/v0.2.5"; }
{ lastModified = 1693509864; lastModifiedDate = "20230831192424"; narHash = "sha256-+olw0aMxsWbsmYvJEBAw2QCS6zPE7YyV46o2Vhn4VsY="; outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; submodules = false; }

nix-repl>

2.3:

Welcome to Nix version 2.3.18. Type :? for help.

nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; }
fetching Git repository 'https://github.com/tbenr/react-native-audio-toolkit'error: cannot update ref 'refs/heads/v2.0.3-status': trying to write non-commit object 53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f to branch 'refs/heads/v2.0.3-status'
error: program 'git' failed with exit code 1



nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "refs/tags/v2.0.3-status"; }
{ outPath = "/nix/store/idsax8hnzcn3pv56x2gmqr5mvy5564xb-source"; rev = "53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f"; revCount = 219; shortRev = "53e823d"; }

nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; }
{ outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; }

nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "refs/tags/v0.2.5"; }
{ outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; }

nix-repl>
It seems to be more complex than this. On Lix and Nix 2.18 alike, `builtins.fetchGit` fails to fetch *any* tag unless it's prefixed with `refs/tags/`, but if can fetch annotated tags if they are prefixed. In Nix 2.3 however, `builtins.fetchGit` can fetch *un*annotated tags unprefixed, but annotated tags need `refs/tags/`. Lix: ```nix Lix 2.90.0-lixpre20240511-a30c567 nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; } fatal: couldn't find remote ref refs/heads/v2.0.3-status error: … while calling the 'fetchGit' builtin at «string»:1:1: 1| builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; } | ^ … while fetching the input 'git+https://github.com/tbenr/react-native-audio-toolkit?ref=v2.0.3-status' error: program 'git' failed with exit code 128 nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "refs/tags/v2.0.3-status"; } { lastModified = 1592064236; lastModifiedDate = "20200613160356"; narHash = "sha256-VLUvxb9xRpMjkfASt4d4UMjnL0HlLb8ZEQKrk4RFZn4="; outPath = "/nix/store/idsax8hnzcn3pv56x2gmqr5mvy5564xb-source"; rev = "53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f"; revCount = 219; shortRev = "53e823d"; submodules = false; } nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; } fatal: couldn't find remote ref refs/heads/v0.2.5 error: … while calling the 'fetchGit' builtin at «string»:1:1: 1| builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; } | ^ … while fetching the input 'git+https://github.com/Qyriad/log2compdb?ref=v0.2.5' error: program 'git' failed with exit code 128 nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "refs/tags/v0.2.5"; } { lastModified = 1693509864; lastModifiedDate = "20230831192424"; narHash = "sha256-+olw0aMxsWbsmYvJEBAw2QCS6zPE7YyV46o2Vhn4VsY="; outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; submodules = false; } nix-repl> ``` 2.18: ```nix Welcome to Nix 2.18.2. Type :? for help. nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; } fatal: couldn't find remote ref refs/heads/v2.0.3-status error: … while calling the 'fetchGit' builtin at «string»:1:1: 1| builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; } | ^ … while fetching the input 'git+https://github.com/tbenr/react-native-audio-toolkit?ref=v2.0.3-status' error: program 'git' failed with exit code 128 nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "refs/tags/v2.0.3-status"; } { lastModified = 1592064236; lastModifiedDate = "20200613160356"; narHash = "sha256-VLUvxb9xRpMjkfASt4d4UMjnL0HlLb8ZEQKrk4RFZn4="; outPath = "/nix/store/idsax8hnzcn3pv56x2gmqr5mvy5564xb-source"; rev = "53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f"; revCount = 219; shortRev = "53e823d"; submodules = false; } nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; } fatal: couldn't find remote ref refs/heads/v0.2.5 error: … while calling the 'fetchGit' builtin at «string»:1:1: 1| builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; } | ^ … while fetching the input 'git+https://github.com/Qyriad/log2compdb?ref=v0.2.5' error: program 'git' failed with exit code 128 nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "refs/tags/v0.2.5"; } { lastModified = 1693509864; lastModifiedDate = "20230831192424"; narHash = "sha256-+olw0aMxsWbsmYvJEBAw2QCS6zPE7YyV46o2Vhn4VsY="; outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; submodules = false; } nix-repl> ``` 2.3: ```nix Welcome to Nix version 2.3.18. Type :? for help. nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "v2.0.3-status"; } fetching Git repository 'https://github.com/tbenr/react-native-audio-toolkit'error: cannot update ref 'refs/heads/v2.0.3-status': trying to write non-commit object 53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f to branch 'refs/heads/v2.0.3-status' error: program 'git' failed with exit code 1 nix-repl> builtins.fetchGit { url = "https://github.com/tbenr/react-native-audio-toolkit"; ref = "refs/tags/v2.0.3-status"; } { outPath = "/nix/store/idsax8hnzcn3pv56x2gmqr5mvy5564xb-source"; rev = "53e823d1bd0dffd7bf799ccfb8fccd3e4023d00f"; revCount = 219; shortRev = "53e823d"; } nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "v0.2.5"; } { outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; } nix-repl> builtins.fetchGit { url = "https://github.com/Qyriad/log2compdb"; ref = "refs/tags/v0.2.5"; } { outPath = "/nix/store/b8kjjfpwx7185wb3bj1x321hjm84h1f2-source"; rev = "b3a69891b7ced1e38a9af2f9e440d37718a92756"; revCount = 38; shortRev = "b3a6989"; } nix-repl> ```
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#152
No description provided.