Zig Fetch ProtocolError?

I’m trying to setup a project as a zig package, but I ran into a problem. I’m on zig v0.13.0 and when I try to fetch my package I get a ProtocolError

$ zig fetch --save git+https://github.com/epizzella/RTOS/tree/zon
error: unable to discover remote git server capabilities: ProtocolError

I’m able to fetch other zig packages so I must have something setup wrong in my repository.

zig.build:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    _ = b.addModule("RTOS", .{
        .root_source_file = b.path("os.zig"),
        .target = target,
        .optimize = optimize,
    });
}

build.zig.zon

.{
    .name = "RTOS",
    .version = "0.0.0",
    .paths = .{"."},
}

You must specify the branch after #.

zig fetch --save git+https://github.com/epizzella/RTOS#zon
3 Likes

I am not sure how to specify the branch with the git+https protocol (in a way that is supported by the protocol).

However using https with a commit specific download url works as a workaround:

zig fetch --save https://github.com/epizzella/RTOS/archive/9d4801c309f5142848f124092034dd59a270e2f5.zip
2 Likes

Thanks you both! Both ways are working for me. I didn’t realize that fetching a branch would be a little different from fetching master.

1 Like

master is fundamentally just another branch. It’s often designated the default branch, but doedn’t have to be. In modern github, it’s “main”, rather than “master”.

If you want stability, the fetch a commit rather than a branch.

When you use the git+https protocol with zig fetch --save it automatically adds the commit hash to the url, so you can use it with a branch and it creates a stable url from that.

1 Like