From patchwork Wed Sep 11 15:18:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13800801 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21901184559 for ; Wed, 11 Sep 2024 15:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067922; cv=none; b=Q/aEwdbbuQ9eHAz0PMw/Mr8Tw4Tk6onSlrb3QsuUrB0XSD9P8AlBsFAmXSpsh5htRmn4yM1+SAnr7HxTh0SeP/Nxk12eSPqvb74onuQsGnFDITRsFdjAyUYIsq/bRD+84aliL6E+ykDOWrcUjky+tvLMEIPYL4uW7OYQ2vWAmq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067922; c=relaxed/simple; bh=mdVJINHqrxD05LIPljBlLCgJeTNHGT4hZXkfExxfRSY=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=mTbyaq00kMChZMKZEs38qpNlKDwHlJhwSkLvy8k+TBmmrlkAIg/ibjRFxRXY6QlpemiRVPTVPoOM6uf3zLE8xPgHZ1YkxCJ3v+9d6vCHcmqRuTkY3H/FjmQNIsUqXquxxCD6tXwkjlHMdrUig0IwqSW5yIDZzmESWi8zcDoZkzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hZUICZUa; arc=none smtp.client-ip=209.85.218.54 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.b="hZUICZUa" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a8d13b83511so597509666b.2 for ; Wed, 11 Sep 2024 08:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726067919; x=1726672719; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=h1pyEkPKv9cCcubpzKkhNNvCflz2zKVGcrV4R9mnLe4=; b=hZUICZUad/cysBqU+D7zkmyAeGmYiYr1L9Lcehf69uoLJJCLaItapGgfCeg+Z4x506 xqPOgYiazODt+Pi1BPWxmx1nKf3hWBZCSywxWw+cADxZlv01QCyX7gLt70ovBwEhtY3l b3iQM1+56s11EoPZliLn9pfMk/tYBS+uHK3FUMIdm5XgvE/HYlewNZ9GJbR3VWY7e1Kr tnu2+H9LN3uYESusMOCYPW0UV7QXHMFk4R5KO0D/du179g0DBFFxyg+QxjLNJwqYYd9R 4UG39n72lg0TRsk+EA/cqGVBEAqEn6R7wmLcTaeyvK28foReeap4p6fxM9RnDG27a//d ZbEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726067919; x=1726672719; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h1pyEkPKv9cCcubpzKkhNNvCflz2zKVGcrV4R9mnLe4=; b=Om9jwaDwicqqgTB0ommHYgTnjU/qKgDCpmM4nxqb20nvwr3rvSmBUflPA1s9onmkL1 Nb5Hy6T6cBm986bAF+lsX1nbM9ThZ6bPnUBAhnlRiqPtcLSCPindQY+Gw6KIHlocRHZ6 JuHUjQNbaJEyR6aip7pKfAzvE5+f1mk4KuhUH22MXVIoxn0RWzPginbzJd1EyGco1X7m GmNaSeBQX0jspSh9gbu0twD8alieWcS0WEchfRNsh66jFGb08iqmX8LuhTTuVVpFxCvS OLGhNNkW+bmUrDG+nYBCodUmsF6yAX9IiV60FwskV/EWl/cNEASqIYOKD55Cr6J+8Wia VI2Q== X-Gm-Message-State: AOJu0Yy/51uwAFSAoAjNjjF5KgF28nUyjY/Ze5853HVxG9Vb4w9+ocA+ FLY1eurU7dZWA42XUtgs1aUZqIFHC4KkkpvQYC8C53BhezX2bki9f9kaSw== X-Google-Smtp-Source: AGHT+IE3nqxL+A2eVKrmQFpv2qgRX39bDU09FotYOtSe8Dond+Maid6SWoy7x4sRdEfqpLH/wP3WXg== X-Received: by 2002:a17:907:94d5:b0:a8d:5ba1:88e6 with SMTP id a640c23a62f3a-a8ffab83db5mr428958266b.28.1726067918879; Wed, 11 Sep 2024 08:18:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25ce9ed6sm618291866b.165.2024.09.11.08.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 08:18:38 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 11 Sep 2024 15:18:34 +0000 Subject: [PATCH 1/4] remote: fix set-branches when no branches are set Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han Jiang , Phillip Wood , Phillip Wood From: Phillip Wood From: Phillip Wood To replace the list of branches to be fetched "git remote set-branches" first removes the fetch refspecs for the remote and then creates a new set of fetch refspecs based and the branches passed on the commandline. When deleting the existing refspecs git_config_set_multivar_gently() will return a non-zero result if there was nothing to delete. Unfortunately the calling code treats that as an error and bails out rather than setting up the new branches. Fix this by not treating a return value of CONFIG_NOTHING_SET as an error. Reported-by: Han Jiang Signed-off-by: Phillip Wood --- builtin/remote.c | 8 ++++++-- t/t5505-remote.sh | 14 +++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index d1f9292ed2b..794396ba02f 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1567,8 +1567,12 @@ static int update(int argc, const char **argv, const char *prefix) static int remove_all_fetch_refspecs(const char *key) { - return git_config_set_multivar_gently(key, NULL, NULL, - CONFIG_FLAGS_MULTI_REPLACE); + int res = git_config_set_multivar_gently(key, NULL, NULL, + CONFIG_FLAGS_MULTI_REPLACE); + if (res == CONFIG_NOTHING_SET) + res = 0; + + return res; } static void add_branches(struct remote *remote, const char **branches, diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 08424e878e1..cfbd6139e00 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -1131,7 +1131,9 @@ test_expect_success 'remote set-branches' ' +refs/heads/next:refs/remotes/scratch/next +refs/heads/seen:refs/remotes/scratch/seen EOF - + cat <<-\EOF >expect.replace-missing && + +refs/heads/topic:refs/remotes/scratch/topic + EOF git clone .git/ setbranches && ( cd setbranches && @@ -1161,14 +1163,20 @@ test_expect_success 'remote set-branches' ' git remote set-branches --add scratch seen && git config --get-all remote.scratch.fetch >config-result && - sort ../actual.respect-ffonly + sort ../actual.respect-ffonly && + + git config --unset-all remote.scratch.fetch && + git remote set-branches scratch topic && + git config --get-all remote.scratch.fetch \ + >../actual.replace-missing ) && test_cmp expect.initial actual.initial && test_cmp expect.add actual.add && test_cmp expect.replace actual.replace && test_cmp expect.add-two actual.add-two && test_cmp expect.setup-ffonly actual.setup-ffonly && - test_cmp expect.respect-ffonly actual.respect-ffonly + test_cmp expect.respect-ffonly actual.respect-ffonly && + test_cmp expect.replace-missing actual.replace-missing ' test_expect_success 'remote set-branches with --mirror' ' From patchwork Wed Sep 11 15:18:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13800803 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9482E1AB53B for ; Wed, 11 Sep 2024 15:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067923; cv=none; b=eYf+YdWw5g/3HONG/cUwRaIYcHA0CaHZGeizsKKMeVr/+5iR/3F6AMJa5upzsJCsUTyaN8xjZIvkx3JL54tRU+jAJjqcuJQIKk9dHKVInxL2pcxf9OSkQQDel7ye7KODeDiwcWn6qgL42Tpgmk4AsPlcWW2j0BZ560rhAzhvbDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067923; c=relaxed/simple; bh=COlog7r+7Vt9Yx+63eZ6yaQJ6rzY4eKyk4XFSzLQP9I=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=MKbREtpPmhqo2OVW/7aC/30PvL9ESPrxcCbm0zVLUQ3dcbeGFPKsPEAbMnwNWjFojU/SUoLKK8m+3OR4gzd45De9GhEZbJA4q+vvYW133/jqA2KhIYNZcjMgVW9zY/fobEXhiKB2zbBXaxBLIFkmZHQ1SU/5DTHE5qQpllupJp0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Cw0ti+bg; arc=none smtp.client-ip=209.85.208.47 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.b="Cw0ti+bg" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c24ebaa427so1680482a12.1 for ; Wed, 11 Sep 2024 08:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726067919; x=1726672719; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=YNBR18b7BGiRB3Ncu48NFZ8PDEckL+7WFNx8Vd+57xQ=; b=Cw0ti+bgZVuKu+lPhjxMi88HwKeeRvcgeYKg6FEvurp8YDdxkaChC2nJor3PQbHWF+ 68XoMqQ6zDxxPlVw9yYprMfhesMGEN9jMzI4HPxkuJDDkLZ6gkdUK9BcfMTK5m95Ttyd im3qe5uzsz1Kmf8q2Rg7LZw9FNFsNfSDehFqZDfbHK/OvnhpJmuYp6ToceMt23D9+MMO dxUvXyoIFiNQP9SOzCUTHfK2vzcu16vWGE8OwKUIWQ2zz/+HFxD5spS0xap6bazXtOJ2 1koAadQ+hamQ8sTf+ahQOowr+JvGUOHPZLQ+eYt6SRhOteuPB2Q3BXGX+lndWQr3tA9b aUig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726067919; x=1726672719; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YNBR18b7BGiRB3Ncu48NFZ8PDEckL+7WFNx8Vd+57xQ=; b=I62+isl2xbo/hJYFLt7nubxRvw+mrR/uuHRl2AE4qJc2IKtPtZjfDmhfaVhMNSi7tB frznOk9Cpm2PXtMn1jVyN9LWTaAIOBRfcVz2PRrtB95Lte117IzD3jH4MEPYbrAjPDqq ltT4O9LXNS7JImM3Iau7l9Ah8/6T3qTj3pHwsoeSuqkkqzqCCXN9PewGP+fSshybxtBi ut07KHDmgzXVdjqudrwouen862/ETsrudb1Vnd2HvLyHBldCbxLsIsXAa4ttCjw5elTj OWzo44rgnTsv3cF6025DlYPKZ9HNxR5cykYAvsejsZ/WUGSCunLT7NuBs6yy1HH3DAIX Ev9A== X-Gm-Message-State: AOJu0YxH56EavgKO00xgOZKnL+BEVXrFCJfbDr1vHv58WlQ+XqvLUIdQ 5uc/4QcRP6+ZbBw18cHzF2ufHKshIOgr+hTaoVNRAfV0yN1AN41tNvKa8g== X-Google-Smtp-Source: AGHT+IGsjsdKJryIGY1XYyP3gzsAo+fIHRWZBiQCTeeJzR67AkIiwPRW1JsynitJOGoM9hNJoJ58HQ== X-Received: by 2002:a17:907:6d09:b0:a7a:8284:c8d6 with SMTP id a640c23a62f3a-a8ffb29987emr524079366b.24.1726067919505; Wed, 11 Sep 2024 08:18:39 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25c72ed3sm624215366b.135.2024.09.11.08.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 08:18:39 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 11 Sep 2024 15:18:35 +0000 Subject: [PATCH 2/4] remote: print an error if refspec cannot be removed Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han Jiang , Phillip Wood , Phillip Wood From: Phillip Wood From: Phillip Wood If the existing fetch refspecs cannot be removed when replacing the set of branches to fetch with "git remote set-branches" the command silently fails. Add an error message to tell the user what when wrong. Signed-off-by: Phillip Wood --- builtin/remote.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/remote.c b/builtin/remote.c index 794396ba02f..4dbf7a4c506 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1603,6 +1603,7 @@ static int set_remote_branches(const char *remotename, const char **branches, } if (!add_mode && remove_all_fetch_refspecs(key.buf)) { + error(_("could not remove existing fetch refspec")); strbuf_release(&key); return 1; } From patchwork Wed Sep 11 15:18:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13800804 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1A962C1A2 for ; Wed, 11 Sep 2024 15:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067924; cv=none; b=e8Bw/dMArqXrwly4VTBFlovUCg4zwug48sYRWvK4AQNIjsgfGFhzbwj1vzwED0Ouos3ENmYd5qGTETF/KT/SFKv8CW92kw2tAPqhYIkwEO75rgNTFSIqi/xavNfHlZqg6/4TK4j1STR1faEr+S99oh6fP5w9nCL+pXLitbnY4bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067924; c=relaxed/simple; bh=rJPzmhMSjx9iBCqP5UsFyGxZtdGbk6iCJqLzSLEXmNQ=; h=Message-Id:In-Reply-To:References:From:Date:Subject:MIME-Version: Content-Type:To:Cc; b=Rlqoa5OEtx9Xs2DH5k9ZzO7GDOx/3DwOU8pNFxaa8BZoABS1hgcYmD8i4LAMdkctQAz56so0Rs3Cv5x2B1oy/Hog4GoxL7flzN9Ul4tWoXP9TLeMAVHNataG/oU0VL54gf12v2iJ1cOvdz+mY9WO6LuGUIXDwyQpWFs4nKbBJCs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SOhjW+GC; arc=none smtp.client-ip=209.85.218.47 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.b="SOhjW+GC" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a8d0d0aea3cso697477466b.3 for ; Wed, 11 Sep 2024 08:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726067921; x=1726672721; darn=vger.kernel.org; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=lUJA/uWC5wEAEvWXWnCz0uXg6YtmJNnjezikMuZ0SGo=; b=SOhjW+GC5tBjTd2+vMJIxbfonX5e8xIhPGGtA8x5Rlmfnuxj8tJIHdGyyyq5XrnzrG iMnWNfFvsJ6w0kiDEAXk2WWAQvGSb4mtTC/x2LYY2HcskYBgE2aihdE8ME8UjeV24BmF HKU4FMcdGEFVM3qI/UfAQufjFdbbuLyZQ311390nrqb2H7cY4rsPObvh2SZ5AZ0JuY+u TleIsg49O+Vey3vHkJBpjXyMULCUR4jX1WcqbZJpXn+Vv8J+/8QOPCz8wc/8cjbAwE+a AsEGrsifsRqsYdRFgU48h8kWqe+U1sjRruFZx5ZxiyU3EZHy5mggMnFS4phsllB3OTfU V7Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726067921; x=1726672721; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lUJA/uWC5wEAEvWXWnCz0uXg6YtmJNnjezikMuZ0SGo=; b=T5SB9ck/m8A1haoX5EcxHp88nKcBp3qvq3r3F5L+GOyqImKJ0Da69wP1fSUDY46Jcp PqQOB2Rq9/YhLjeOiud3Dh6hJTt/xw3cPtsV5W1vasg1CvvqaU2tt4gRCFfHYLSY1Afc 3vQYWQB89iNz8NYKoKoibWN5EcgCnKE273f4JVPOYGwqNiH1Z3wAxdqMCXeue1bUGrom XX9rWQyzu26BR2tuAQwmswH0jXLZJM/n2XLnqzi5U6t4lVW14MWYdo5LPs9qTu50zTdT YJEMGO6tCU4CyoKIgK3DZKezvu8cEXWTlGExXQ4+1JL03XGpYeiRpM25Vb8CfdLa4Wh2 YXLg== X-Gm-Message-State: AOJu0YyF8KDClecmlWx4Tm4loxLIMqYDClfYwnYK1apd4llPI5ydXljx CVw1pnQhY/K/85+gjK/0KNNEWrSg5F9K93tW/a3jHsesWHEDTIJFJSQEug== X-Google-Smtp-Source: AGHT+IHuWbi2oQ6vnS7Q2ZOSl/7nR2wcY/jSBdZivQJ2uP0UIZLUfkWN4n4xoO3Zu/W8tLLZ3Embkg== X-Received: by 2002:a17:907:3d8e:b0:a8d:4e13:55f9 with SMTP id a640c23a62f3a-a8ffaae3670mr491474266b.19.1726067920832; Wed, 11 Sep 2024 08:18:40 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d3b47d270sm563479666b.47.2024.09.11.08.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 08:18:39 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 11 Sep 2024 15:18:36 +0000 Subject: [PATCH 3/4] remote add: use strvec to store tracking branches Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Han Jiang , Phillip Wood , Phillip Wood From: Phillip Wood From: Phillip Wood Store the list of branches to track in a ’struct strvec' instead of a 'struct string_list'. This in preparation for the next commit where it will be convenient to have them stored in a NULL terminated array. This means that we now duplicate the strings when storing them but the overhead is not significant. Signed-off-by: Phillip Wood --- builtin/remote.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 4dbf7a4c506..318701496ed 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -158,7 +158,7 @@ static int add(int argc, const char **argv, const char *prefix) { int fetch = 0, fetch_tags = TAGS_DEFAULT; unsigned mirror = MIRROR_NONE; - struct string_list track = STRING_LIST_INIT_NODUP; + struct strvec track = STRVEC_INIT; const char *master = NULL; struct remote *remote; struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; @@ -171,8 +171,8 @@ static int add(int argc, const char **argv, const char *prefix) N_("import all tags and associated objects when fetching\n" "or do not fetch any tag at all (--no-tags)"), TAGS_SET), - OPT_STRING_LIST('t', "track", &track, N_("branch"), - N_("branch(es) to track")), + OPT_STRVEC('t', "track", &track, N_("branch"), + N_("branch(es) to track")), OPT_STRING('m', "master", &master, N_("branch"), N_("master branch")), OPT_CALLBACK_F(0, "mirror", &mirror, "(push|fetch)", N_("set up remote as a mirror to push to or fetch from"), @@ -210,10 +210,9 @@ static int add(int argc, const char **argv, const char *prefix) strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", name); if (track.nr == 0) - string_list_append(&track, "*"); + strvec_push(&track, "*"); for (i = 0; i < track.nr; i++) { - add_branch(buf.buf, track.items[i].string, - name, mirror, &buf2); + add_branch(buf.buf, track.v[i], name, mirror, &buf2); } } @@ -246,7 +245,7 @@ static int add(int argc, const char **argv, const char *prefix) strbuf_release(&buf); strbuf_release(&buf2); - string_list_clear(&track, 0); + strvec_clear(&track); return 0; } From patchwork Wed Sep 11 15:18:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13800805 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4554E1AC88A for ; Wed, 11 Sep 2024 15:18:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067927; cv=none; b=LYaRGB+quZlrtJmmkf5ru0ZFkVU5rAtjk8656GQOH0mpS22bYrM7Y3vLzDqCg6Sxl7yHq+s6VyfYIhNnehyvXx2DCU43K/VcznuT9c2REQ3v3g9bGiEiekKpdjoJ/a54aXhxY5l5BBqKwnzPChIrBZyq2lS7nmed3dlmQwwnHNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726067927; c=relaxed/simple; bh=5l7+6IXecgG9a39NXmei0JZpyMe9KreCYAEWnFLSE6c=; h=Message-Id:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=inkbJvwl1WiSaYN7G2HkuQuG3QaRob3FXQgpbbmtrTNnMKJUj9gE2GwVSetI3KrXEtbtvWMJrvdoN7UhhtUIEgG0pmfN8Ai7kj19Tv/cV2gSlspgtTzd4F9B4FfWEQT2SK3n3cYkSwfEl8nrh2fsoxo6l5PDPD3jpLG6AHXwZ84= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IfLFbpe3; arc=none smtp.client-ip=209.85.208.170 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.b="IfLFbpe3" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2f75428b9f8so22919111fa.3 for ; Wed, 11 Sep 2024 08:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726067923; x=1726672723; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=wwLU6yfkT1MAzSPpvvvUTy0XWobCnJbo32cIIv0rM6g=; b=IfLFbpe3wCSCUfu5XeY0yv8Kqm/lseDZd8XNiw9nurVYQljk3qX/AX9+z6a8I1p/bc /XrjwSKsMFPBejG+5L55UqTJJhmsmFk4mrpLbu9MyUEoiEiJ8Lts6beoLydmbx6zUN6/ bk9jsqMcM3F8e65UxU/q3YHSzRTnd8zEOTw0WabPyqfEAs758P8xO5oCwRIiN/wc5hzw /TbXckxByKz54JT3ESoWIeEggAKddnCNbUAJc+UIlOVJcCK9qc7zBFMKTPbqNbaS7TKb IP/YBwr/6JJH1DSB5CcKOrG6KVYL44OKo8rl8iK+cZOgWQInbzAFbYNb7F08kMeRt+Ms 5woA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726067923; x=1726672723; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wwLU6yfkT1MAzSPpvvvUTy0XWobCnJbo32cIIv0rM6g=; b=w0YaEkjruIBp7NLOgkWM/GDxh53OueAGjkL740ct3/fcUhyIKrTg8k4xT9b3pU3rbR tgK/ubKQ1x5PeiFFtyYlBNdHK+F4eYG3m8rO4gkI0JyHioDRIWOTGQV7kBsVV28i5PUs /GDPHrb8ZKLG2BxA48pCG43D+s4tweSLNNsusSu0BVXagV0W3gewsIg7mfbykIHhYpHg ejUOKIJNXrp/i5xYFoSpISYSWoGU1yaf4FlzamjjmhjvzBlEYLM3HMvVHSWyNPc1ku+s 0q4M7OhQC1MGWi72DnVLXGGCuCk+6k7UYPXNufy+KXWFXE3P+0TLDGvOLuhGF/2URTu6 3mpg== X-Gm-Message-State: AOJu0Yz99m3EmFNT73fz2psSmOzs1ATIGtif3i1nJUmUA7RPq1/YHN0E nj4kbk/ea3VyBWsxYfdK5ie39HTZU8ifH+fKQG805tnu563AYsjh6bmQww== X-Google-Smtp-Source: AGHT+IEeJdY0XV4sVcOM5aTv4oMhyotS0SR7ycOG93z1qnaEYzn0o7kt6bfYTbXh6sEgk41b3aPfEA== X-Received: by 2002:a05:6512:2244:b0:530:ab68:25c5 with SMTP id 2adb3069b0e04-536587a689fmr18862005e87.2.1726067922080; Wed, 11 Sep 2024 08:18:42 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d258317d6sm623379166b.29.2024.09.11.08.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 08:18:41 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 11 Sep 2024 15:18:37 +0000 Subject: [PATCH 4/4] remote: check branch names Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Han Jiang , Phillip Wood , Phillip Wood From: Phillip Wood From: Phillip Wood Make sure the names passed to "git remote add -t " and "git remote set-branches " are syntactically valid so that we do not create invalid refspecs. This check needs to be performed before creating the remote or modifying the existing configuration so a new function is added rather than modifying add_branch() Tests are added for both commands that to ensure (i) we report all the invalid branch names passed on the command line, (ii) the branch names are validated before modifying the configuration and (iii) wildcards are accepted. Signed-off-by: Phillip Wood --- builtin/remote.c | 19 +++++++++++++++++++ t/t5505-remote.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/builtin/remote.c b/builtin/remote.c index 318701496ed..fd84bfbfe7a 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -132,6 +132,19 @@ static void add_branch(const char *key, const char *branchname, git_config_set_multivar(key, tmp->buf, "^$", 0); } +static int check_branch_names(const char **branches) +{ + int ret = 0; + + for (const char **b = branches; *b; b++) { + if (check_refname_format(*b, REFNAME_ALLOW_ONELEVEL | + REFNAME_REFSPEC_PATTERN)) + ret = error(_("invalid branch name '%s'"), *b); + } + + return ret; +} + static const char mirror_advice[] = N_("--mirror is dangerous and deprecated; please\n" "\t use --mirror=fetch or --mirror=push instead"); @@ -203,6 +216,9 @@ static int add(int argc, const char **argv, const char *prefix) if (!valid_remote_name(name)) die(_("'%s' is not a valid remote name"), name); + if (check_branch_names(track.v)) + exit(128); + strbuf_addf(&buf, "remote.%s.url", name); git_config_set(buf.buf, url); @@ -1601,6 +1617,9 @@ static int set_remote_branches(const char *remotename, const char **branches, exit(2); } + if (check_branch_names(branches)) + exit(128); + if (!add_mode && remove_all_fetch_refspecs(key.buf)) { error(_("could not remove existing fetch refspec")); strbuf_release(&key); diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index cfbd6139e00..709cbe65924 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -1195,6 +1195,34 @@ test_expect_success 'remote set-branches with --mirror' ' test_cmp expect.replace actual.replace ' +test_expect_success 'remote set-branches rejects invalid branch name' ' + git remote add test https://git.example.com/repo && + test_when_finished "git config --unset-all remote.test.fetch; \ + git config --unset remote.test.url" && + test_must_fail git remote set-branches test "topic/*" in..valid \ + feature "b a d" 2>err && + cat >expect <<-EOF && + error: invalid branch name ${SQ}in..valid${SQ} + error: invalid branch name ${SQ}b a d${SQ} + EOF + test_cmp expect err && + git config --get-all remote.test.fetch >actual && + echo "+refs/heads/*:refs/remotes/test/*" >expect && + test_cmp expect actual +' + +test_expect_success 'remote add -t rejects invalid branch name' ' + test_must_fail git remote add test -t .bad -t "topic/*" -t in:valid \ + https://git.example.com/repo 2>err && + cat >expect <<-EOF && + error: invalid branch name ${SQ}.bad${SQ} + error: invalid branch name ${SQ}in:valid${SQ} + EOF + test_cmp expect err && + test_expect_code 1 git config --get-regexp ^remote\\.test\\. >actual && + test_must_be_empty actual +' + test_expect_success 'new remote' ' git remote add someremote foo && echo foo >expect &&