Skip to content

Repo cloned by gix clone --depth 1 is larger than git clone --depth 1 #2227

@MrConnorKenway

Description

@MrConnorKenway

Current behavior 😯

In current implementation of fetch_only, the refspecs is hardcoded to +refs/heads/*:refs/remotes/{remote_name}/* even when shallow cloning. As a result, the cloned repo is significantly larger than repo cloned by git.

Expected behavior 🤔

The repo size and fetch config should be the same with git

Git behavior

In git's implementation (https://github.com/git/git/blob/133d151831d32bdcc02422599a3f26cef44f929b/builtin/clone.c#L810), the fetch config varies based on the option:

		if (option_single_branch && !option_mirror) {
			if (option_branch) {
				if (starts_with(our_head_points_at->name, "refs/tags/"))
					strbuf_addf(&value, "+%s:%s", our_head_points_at->name,
						our_head_points_at->name);
				else
					strbuf_addf(&value, "+%s:%s%s", our_head_points_at->name,
						branch_top->buf, option_branch);
			} else if (remote_head_points_at) {
				const char *head = remote_head_points_at->name;
				if (!skip_prefix(head, "refs/heads/", &head))
					BUG("remote HEAD points at non-head?");

				strbuf_addf(&value, "+%s:%s%s", remote_head_points_at->name,
						branch_top->buf, head);
			}
			/*
			 * otherwise, the next "git fetch" will
			 * simply fetch from HEAD without updating
			 * any remote-tracking branch, which is what
			 * we want.
			 */
		} else {
			strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top->buf);
		}
		/* Configure the remote */
		if (value.len) {
			strbuf_addf(&key, "remote.%s.fetch", remote_name);
			repo_config_set_multivar(the_repository, key.buf, value.buf, "^$", 0);
			strbuf_reset(&key);

			if (option_mirror) {
				strbuf_addf(&key, "remote.%s.mirror", remote_name);
				repo_config_set(the_repository, key.buf, "true");
				strbuf_reset(&key);
			}
		}

Steps to reproduce 🕹

  1. Run gix clone --depth 1 https://github.com/GitoxideLabs/gitoxide
  2. The size of cloned gitoxide is about 130MB and the fetch config is fetch = +refs/heads/*:refs/remotes/origin/*. Running git tag inside gitoxide shows a lot of tags.
  3. Run git clone --depth 1 https://github.com/GitoxideLabs/gitoxide
  4. The size of gitoxide is about 70MB and the fetch config is fetch = +refs/heads/main:refs/remotes/origin/main. git tag shows nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedan issue is accepted as shortcoming to be fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions