From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796046741; b=OQIuvGbymrLgqq6YjlsT1ooD2d0fDYZh3IT8muaa0evZ7oVSzHF3yKFyyNvVkJ0jQBUA KtkVCRwlwziDDWXgKwX/lVfKSAFJOubud8x/Q05bx6omVFTjZOfSCOqwOX7FCXsGI2Vvn 5Oegett+hGWQcSdm9wEKOza5AQNFUe0bUaoTKwXZvbky1q3vgeeVagefWL9ID0o2ZfkoH H06zu49ork7ZmGb5gnZa+jSHL41cQJLDBWKfhEaUSS7lr+SV9cnXnxu0OtgDib8Lm3M+t maFUcHV3CtHv/3K9ryXfZktq/VQiiS0G6qdlLnbCkdC/E8pCUdv+XM38/+HAlD6bYow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796046741; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=; b=g3RUL5Y80FPh+SVkFXDMn8dUooyTQqUvPtvjJjqrTmWcTmq61oQRy3YHzSB5fVkT7xwt h31O6z4h1lcBfYRJN/VsWKiT2X5z/2cl9OHfNePAX0+eWVWn6ivYKPoXLUCrqYh2LHfxa HOHg+6WJU7kiD8GHDDTr4qjeqsw7Mj0vuR1doFQoE1yiaovZDVCBdLyP1nWLjaU39svAI 2Wrjt8Fd+clvzeoLFquhsRm8v6Mza7NnpLu/EiMpqc1MlgXyRa3h/lA1qAJN0UobraW7M QBw3SJGplMHL/Cx2R/mJ9KyZbkL7UXhBVB8Nszt7q9/FPhlkvoX5c37p8okJR6oRitw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="K8hv/FAd"; arc=none smtp.remote-ip=209.85.210.180 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B246B606A31C for ; Mon, 30 Nov 2026 13:52:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B246B606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=K8hv/FAd Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-8b4c8b51b58so6240227b3a.1 for ; Mon, 30 Nov 2026 05:52:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796046740; x=1796651540; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=; b=K8hv/FAddbZH29IlQ+koQmVrF25C8bHrynNkgMzjVEpe2JHWEqSyOdAlgB51kUbL9z 4qD7mN3y6CIUylCVnL+DZSbGK37dO3STWHvWazCt2ppJyvbkbLalvn6BElZtxdO8BgGI fCawRlomm4fbNpdkESHhQPMnl4PLByUHNHEFHVhtRzIFwuxTwVtfHWkOcZ/BuOyDpzN6 s3fbcMnY78TWuveMZ/thPRhfHK6oLZwMEzmCic8IJXXUpXThLwM/1uZ8ijl1B9A1N8/4 utbc3hIBfioEIsdI7ABgG27OR/b2u9kbrgmWDBNzW9AMZG43U3txaEztpxTeMu8DYd1y 6H0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796046740; x=1796651540; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Z0Akfym+JPHTsS7/MhXnnLGPx6jZ8aVxbXnnuCNSxZ4=; b=c+jpBsRvgnt8NBENk8EwoxRjnWz+i28dGxHKW/mSw62MvHR8KW6M9Gj/jyvYVy9aR7 4b/7EJtD4a48IDgFQLjWgoYGX/PbyW9bBDwMHuOwpKsr0ry2F57yVkNPtBIIYHOXaK7u 4nAs/nJ92hyfk6h5bxhZOdmvQvF2pYl6upfCVKHKg2UO1q4dsmUZHSlh8149FsZt9Y7u L6gg3bOoSModTI3Y+WqaQuYIDcU9cLEpS3ze+FNNn6SRuNEUCappNndoNYoYF486IuCC 7w7EIp2TjR6E9nxtsXhMhbFFX5CO8xkxOrCJ0YUtpiUVdEwC2hW/0nWwMiQRPZ+hdiMD pxTw== X-Gm-Message-State: APuU4Z8daqCrLh/R+co4IF1ClqJOLPR4bNL360d/F5aoawwkQVYkwC4g pxdL7MtX0fP7PIM+sKaB9N/r+QWkPE0Jn8OoszjcO+01syESmlIw1cUBpd+RcLId X-Gm-Gg: AZFdTZek/zsFqdBR/H81FZ7PeR+o5eAXYyapKcm34UWiDQdpVLzapvW52uzBQax9KUq C2fWciTsAzt94AmdqQFZHDG/wwJhUeAi/IbUa4+b+RNNm+aFTfyYFvxKHVuflcz0xBjs5oRPpjV uJ56vpwEpRMvmD0zGDzyXB3A08NNqZ7LxHRrpZvT/jMEPdyBltYt8l42p4bZcJMbI8dSX2gBWGY G424QXSakNzi4zvEsc59CoVYsGylmtTVfhCCFiY9R6nfqnN9B0y0lJo757Ra1/CnuTaIfkojsP7 HsJCIKrP5kxiKQeY4Oy2kWK84cyr5jtfPM1VW2ZOHDVhkIiGtQxO1biU1nSjmPlzEMvKNaZGBAG i3ZtZty57Rs2nG3z0RPFB4d6G41pJi4v3oLjWLAlsG8d5L4g0IGwvqBIpsuYaMaDJ6+OGdbc50W ON5HETMmjmRv/lN23t/OlGA668tq/aBb+aQkZe365T6LSEDawNpsH5ksoufvxZB+hxG8DYNXQNP ONnlKVkc1xLy4729v07ULq8U2fjeIYFm7h2/K1W4OT0AyK+LGPKNye69Q+Fx+FoqlXiYIFDdD71 VCKxNoVfvG7LD4JvYhtIvR55bUP/ZVw= X-Received: by 2002:a05:690e:812:10b0:679:9bc4:cc03 with SMTP id 956f58d0204a3-67df4452f0cmr9371980d50.69.1796046384997; Mon, 30 Nov 2026 05:46:24 -0800 (PST) Received: from [127.0.0.1] ([20.49.63.207]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-921787fd72asm156997366d6.12.2026.11.30.05.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:46:24 -0800 (PST) Message-Id: <49ec3aaed9940c56724943501be7b06e6402bcbd.1796046376.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Harald Nordgren via GitGitGadget" Date: Mon, 30 Nov 2026 13:46:16 +0000 Subject: [PATCH v17 7/7] remote: default to --limited-fetch in a shallow repository Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , "D. Ben Knoble" , Matt Hunter , Kristoffer Haugsbakk , Harald Nordgren , Harald Nordgren From: Harald Nordgren Adding a second remote to a shallow clone used to still fetch every branch that remote has, since "git remote add" always set up a wildcard remote..fetch refspec regardless of how shallow the repository already was. That defeats the purpose of having cloned shallow in the first place (for example with --single-branch), and can make a plain "git fetch" on that remote hang or take a very long time on a repository with many branches. Turn --limited-fetch on by default when the repository is already shallow and neither -t/--track nor --mirror was given, so that adding a remote there does not by itself commit to following every branch it has. --no-limited-fetch keeps the previous behavior for whoever wants it. Signed-off-by: Harald Nordgren --- Documentation/git-remote.adoc | 9 +++++- builtin/remote.c | 5 ++- t/t5505-remote.sh | 60 +++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Documentation/git-remote.adoc b/Documentation/git-remote.adoc index 39b9281293..2216a2a752 100644 --- a/Documentation/git-remote.adoc +++ b/Documentation/git-remote.adoc @@ -57,6 +57,11 @@ Add a remote named __ for the repository at __. The command `git fetch ` can then be used to create and update remote-tracking branches `/`. + +If the repository is already a shallow repository (see linkgit:git-clone[1] +`--depth`) and neither `-t`, `--mirror` nor `--no-limited-fetch` is given, +`--limited-fetch` is turned on by default, so that `git fetch ` does +not need to negotiate history for every branch the remote has. ++ With `-f` option, `git fetch ` is run immediately after the remote information is set up. + @@ -79,7 +84,9 @@ With `--limited-fetch` option, instead of a `remote..fetch` refspec that tracks all branches, `remote..fetchRefmap` and `remote..fetchUpstreams` are set up so that a refspec-less `git fetch ` only fetches branches our local branches are built -on. See linkgit:git-config[1] for details. +on. See linkgit:git-config[1] for details. `--no-limited-fetch` +explicitly disables this, overriding the shallow-repository default +described above. + With `-m ` option, a symbolic-ref `refs/remotes//HEAD` is set up to point at remote's __ branch. See also the set-head command. diff --git a/builtin/remote.c b/builtin/remote.c index 18fe6f697c..8163fcc618 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -16,6 +16,7 @@ #include "rebase.h" #include "refs.h" #include "refspec.h" +#include "shallow.h" #include "odb.h" #include "strvec.h" #include "commit-reach.h" @@ -238,7 +239,9 @@ static int add(int argc, const char **argv, const char *prefix, if (!mirror || mirror & MIRROR_FETCH) { bool use_limited_fetch = mirror == MIRROR_NONE && track.nr == 0 && - limited_fetch == 1; + (limited_fetch == 1 || + (limited_fetch == -1 && + is_repository_shallow(the_repository))); strbuf_reset(&buf); if (use_limited_fetch) { diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 679d22fcec..61cb53a589 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -144,6 +144,66 @@ test_expect_success 'filters are listed by git remote -v only' ' test_grep ! "\[blob:none\]" out ' +test_expect_success 'add remote -t keeps an explicit refspec in a shallow repository' ' + test_when_finished "rm -rf shallow-add" && + git clone --no-local --depth=1 --branch main --single-branch \ + one shallow-add && + ( + cd shallow-add && + git remote add -t main upstream ../two && + test_cmp_config "+refs/heads/main:refs/remotes/upstream/main" \ + remote.upstream.fetch + ) +' + +test_expect_success 'add remote keeps the wildcard refspec in a full repository' ' + test_when_finished "rm -rf full-add" && + git clone --no-local one full-add && + ( + cd full-add && + git remote add upstream ../two && + test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \ + remote.upstream.fetch + ) +' + +test_expect_success 'a remote added in a shallow repository defaults to --limited-fetch' ' + test_when_finished "rm -rf shallow-add" && + git clone --no-local --depth=1 --branch main --single-branch \ + one shallow-add && + ( + cd shallow-add && + git remote add upstream ../two && + test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \ + remote.upstream.fetchRefmap && + test_cmp_config true remote.upstream.fetchUpstreams && + test_must_fail git config get remote.upstream.fetch && + git fetch upstream main && + git branch --set-upstream-to=upstream/main && + git fetch upstream && + git for-each-ref --format="%(refname)" refs/remotes/upstream >actual && + cat >expect <<-\EOF && + refs/remotes/upstream/HEAD + refs/remotes/upstream/main + EOF + test_cmp expect actual + ) +' + +test_expect_success '--no-limited-fetch overrides the shallow-repository default' ' + test_when_finished "rm -rf shallow-add" && + git clone --no-local --depth=1 --branch main --single-branch \ + one shallow-add && + ( + cd shallow-add && + git remote add --no-limited-fetch upstream ../two && + test_cmp_config "+refs/heads/*:refs/remotes/upstream/*" \ + remote.upstream.fetch && + test_must_fail git config get remote.upstream.fetchRefmap && + test_must_fail git config get remote.upstream.fetchUpstreams + ) +' + test_expect_success '--limited-fetch works in a full repository too' ' test_when_finished "rm -rf full-add" && git clone --no-local one full-add && -- gitgitgadget