Skip to content

Fix head reference in zig fetch commands#74

Merged
rockorager merged 1 commit into
rockorager:mainfrom
AloisMahdal:fix_fetch_commands
Jun 13, 2026
Merged

Fix head reference in zig fetch commands#74
rockorager merged 1 commit into
rockorager:mainfrom
AloisMahdal:fix_fetch_commands

Conversation

@AloisMahdal

Copy link
Copy Markdown
Contributor

This syntax:

URL?ref=REF

is what ends up in the build.zig.zon, but does not work when used on the command line. What works on command line is:

URL#REF

E.g. following test:

$ grep 'rock\|zeit-' build.zig.zon
$ zig fetch --save git+https://github.com/rockorager/zeit?ref=main
info: resolved to commit 905396257dcf0b1bfa3c0e8265657a0e748105ad
$ grep 'rock\|zeit-' build.zig.zon
            .url = "git+https://github.com/rockorager/zeit?ref=main#905396257dcf0b1bfa3c0e8265657a0e748105ad",
            .hash = "zeit-0.10.0-dev-5I6bk3m9AgB8Ndev81pibV70MJe9VCOXAGZBNU833c4Y",
$ zig fetch --save git+https://github.com/rockorager/zeit?ref=v0.9.0
info: resolved to commit 905396257dcf0b1bfa3c0e8265657a0e748105ad
warning: overwriting existing dependency named 'zeit'
$ grep 'rock\|zeit-' build.zig.zon
            .url = "git+https://github.com/rockorager/zeit?ref=v0.9.0#905396257dcf0b1bfa3c0e8265657a0e748105ad",
            .hash = "zeit-0.10.0-dev-5I6bk3m9AgB8Ndev81pibV70MJe9VCOXAGZBNU833c4Y",
$ zig fetch --save git+https://github.com/rockorager/zeit#v0.9.0
info: resolved ref 'v0.9.0' to commit b1c1c2fcbc71fd7799a316bbcf0ff88d06d80ccc
warning: overwriting existing dependency named 'zeit'
$ grep 'rock\|zeit-' build.zig.zon
            .url = "git+https://github.com/rockorager/zeit?ref=v0.9.0#b1c1c2fcbc71fd7799a316bbcf0ff88d06d80ccc",
            .hash = "zeit-0.9.0-5I6bk2m9AgBSMH8-L6rYJkwuQAyhXplnfxnvTSGzVHUR",
$

shows that:

  1. on empty build.zig.zon, using ?ref=main fetches main

  2. then ?ref=v0.9.0 still fetches main, it just updates URL but leaves commit reference and package hash untouched

  3. correct form #v0.9.0 will update URL, commit reference and package hash.

This syntax:

    URL?ref=REF

is what ends up in the build.zig.zon, but does *not* work when used on
the command line.  What works on command line is:

    URL#REF

E.g. following test:

    $ grep 'rock\|zeit-' build.zig.zon
    $ zig fetch --save git+https://github.com/rockorager/zeit?ref=main
    info: resolved to commit 9053962
    $ grep 'rock\|zeit-' build.zig.zon
                .url = "git+https://github.com/rockorager/zeit?ref=main#905396257dcf0b1bfa3c0e8265657a0e748105ad",
                .hash = "zeit-0.10.0-dev-5I6bk3m9AgB8Ndev81pibV70MJe9VCOXAGZBNU833c4Y",
    $ zig fetch --save git+https://github.com/rockorager/zeit?ref=v0.9.0
    info: resolved to commit 9053962
    warning: overwriting existing dependency named 'zeit'
    $ grep 'rock\|zeit-' build.zig.zon
                .url = "git+https://github.com/rockorager/zeit?ref=v0.9.0#905396257dcf0b1bfa3c0e8265657a0e748105ad",
                .hash = "zeit-0.10.0-dev-5I6bk3m9AgB8Ndev81pibV70MJe9VCOXAGZBNU833c4Y",
    $ zig fetch --save git+https://github.com/rockorager/zeit#v0.9.0
    info: resolved ref 'v0.9.0' to commit b1c1c2f
    warning: overwriting existing dependency named 'zeit'
    $ grep 'rock\|zeit-' build.zig.zon
                .url = "git+https://github.com/rockorager/zeit?ref=v0.9.0#b1c1c2fcbc71fd7799a316bbcf0ff88d06d80ccc",
                .hash = "zeit-0.9.0-5I6bk2m9AgBSMH8-L6rYJkwuQAyhXplnfxnvTSGzVHUR",
    $

shows that:

  1. on empty build.zig.zon, using `?ref=main` fetches main

  2. then `?ref=v0.9.0` *still* fetches main, it just updates URL but
     leaves commit reference and package hash untouched

  3. correct form `#v0.9.0` will update URL, commit reference and
     package hash.
@AloisMahdal

Copy link
Copy Markdown
Contributor Author

Note that I've reported the zig fetch "footgun" to zig: https://codeberg.org/ziglang/zig/issues/35756

@rockorager rockorager merged commit ccef3c2 into rockorager:main Jun 13, 2026
4 checks passed
@AloisMahdal AloisMahdal deleted the fix_fetch_commands branch June 14, 2026 13:58
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