From patchwork Sat Mar 30 14:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13611584 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.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 806718BFC for ; Sat, 30 Mar 2024 14:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711807656; cv=none; b=YqraMa0nZbpb1HrVyeGuUV3E/Ey3kLfpDR4oLYZBMFanCl7jSxQhFpyC5eAOdY/2BE5TDi9lnr4GcPkD4zFODyQcoxUHqrj6LKmhJH+2j9DueOssWUWaAVb+e/BJpQiduQ2KEjMMjBDrJu7r127bcZ0cJgJ0MSlvvuybgILcJ0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711807656; c=relaxed/simple; bh=fEz7zdPwhXxZLCVZebQGWMb5LNJ1BpgIhan16VBXCoM=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=cCFHgQrNi4n02GAzKl6CsRoBBRlFjlvBQQ5ddPfCDwJkrrB1sem61cgfXPDRXbYo5eF2RdcJiC/R80pvO+eKNbXfsSH1ZiX7vaaaUBcKBLT9WJkulOWToT9psA8lT0EsibWkWUN37llg+pAdQOuo91Z9uitUMb02z6Wm2zawB+k= 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=WxUQGW7q; arc=none smtp.client-ip=209.85.128.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="WxUQGW7q" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4154471fb81so16987295e9.0 for ; Sat, 30 Mar 2024 07:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711807653; x=1712412453; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=bL1hXjK15JCWDNRC19wXu5puvSd65tC1jfX/7ApKFNI=; b=WxUQGW7q1wxnzsalrmztdsDMhVxKJLf20fscAfft4UYhkEPMjUWTKbZ+VSn0rXFnll fCWbiRnjWDPCjcM8eRGyeFwsc4W/V0h0XKTMEBZY8yTz4ZoylaFgtdw5xitiZVoHrTPj PfzPTVhjW0PgLmWFWFaZsCX0LEVhh0OD/Vi9WfQuALDcc77uzphTdY+sK+s5Ytp86hUe fj/s4l657mtP3fTjxMwTlgpCPVbhiAqyK/LTQfSaAbiHbXLyV3OqxC++tDTntGpGDOww cECsVPb9SbrAT7fUBQRoXTQXXGt8covQFC9YeP4ENtT6+1gI/n2ydsDPvbs8/QchJwuu 30Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711807653; x=1712412453; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bL1hXjK15JCWDNRC19wXu5puvSd65tC1jfX/7ApKFNI=; b=qH7ifSDXoHOKVNQ0VqIGuN+FF/kNqLCTkL5/y7URTmLN9DT1DjMRBq0oE0MIpjRcVD p5J3jcO56xV0o2q+sTWNK2yV+GuUvO//l9Af0Yz4BwTMhwkzHgfm2xmitaPqgR5N6KsR POPv0T7EQa35PKq8jMqwlEh7VAHSJqjV/LBgqcqI0IXdEJDSPmFdsoFMYZUCbUHwa7i2 uuTOkh/c6QtroO/6cwBpbt5t6oR3MdAqmj7KjasedF+wqQ+BHXNvPU4ogIjoSiVhQDU9 gk5f0TRwLpju11sVZPIc/Aqn8AT3/Itd5AAFdcwRCmgGN7lwTq2mD7FfZymfQ/UsI7Gb PIZg== X-Gm-Message-State: AOJu0Yw151koKJBxDww3kF/ewTnbObm2NXZGJ8mKmSQKwtvpGWzYEaJ8 5rDY1GySnAJDZfAAOV/NggiYOojkPcT7Qq3Fow5tEQKrv21Gf+q4YeJJ45N8 X-Google-Smtp-Source: AGHT+IE15tdm1J/5POhkXFkyFPs0NpkLCCVh2lCDdzgt8J3mIO7vcty1qXO5sNWLDtwupWjLhGZ9FA== X-Received: by 2002:a05:600c:3c99:b0:414:8e3:d8e0 with SMTP id bg25-20020a05600c3c9900b0041408e3d8e0mr4085481wmb.17.1711807652739; Sat, 30 Mar 2024 07:07:32 -0700 (PDT) Received: from gmail.com (40.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.40]) by smtp.gmail.com with ESMTPSA id v13-20020a05600c444d00b0041493b57976sm8603851wmn.18.2024.03.30.07.07.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Mar 2024 07:07:32 -0700 (PDT) Message-ID: <57bbf2a2-1596-4b7c-a467-82b7b5b22a20@gmail.com> Date: Sat, 30 Mar 2024 15:07:27 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 1/3] add: use advise_if_enabled for ADVICE_ADD_IGNORED_FILE Content-Language: en-US From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <06c9b422-b22e-4310-ad5b-1686616ab860@gmail.com> <46fba030-d7aa-49d2-88fa-e506850f7b6a@gmail.com> In-Reply-To: <46fba030-d7aa-49d2-88fa-e506850f7b6a@gmail.com> Since b3b18d1621 (advice: revamp advise API, 2020-03-02), we can use advise_if_enabled() to display an advice. This API encapsulates three actions: 1.- checking the visibility of the advice 2.- displaying the advice when appropriate 3.- displaying instructions on how to disable the advice, when appropriate The code we have in builtin/add.c to display the ADVICE_ADD_IGNORED_FILE advice, is doing these three things. However, the instructions displayed on how to disable the hint are not shown in the normalized way that advise_if_enabled() introduced. This may cause distraction. There is no reason not to use the new API here. On the contrary, by using it we gain simplicity in the code and avoid possible distractions. For these reasons, use the newer advise_if_enabled() machinery to show the ADVICE_ADD_IGNORED_FILE advice, and don't bother checking the visibility or displaying the instruction on how to disable the advice. Signed-off-by: Rubén Justo --- builtin/add.c | 6 ++---- t/t3700-add.sh | 3 +-- t/t7400-submodule-basic.sh | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 393c10cbcf..8f148987f7 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -328,10 +328,8 @@ static int add_files(struct dir_struct *dir, int flags) fprintf(stderr, _(ignore_error)); for (i = 0; i < dir->ignored_nr; i++) fprintf(stderr, "%s\n", dir->ignored[i]->name); - if (advice_enabled(ADVICE_ADD_IGNORED_FILE)) - advise(_("Use -f if you really want to add them.\n" - "Turn this message off by running\n" - "\"git config advice.addIgnoredFile false\"")); + advise_if_enabled(ADVICE_ADD_IGNORED_FILE, + _("Use -f if you really want to add them.")); exit_status = 1; } diff --git a/t/t3700-add.sh b/t/t3700-add.sh index f23d39f0d5..76c2c9e7b0 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -370,8 +370,7 @@ cat >expect.err <<\EOF The following paths are ignored by one of your .gitignore files: ignored-file hint: Use -f if you really want to add them. -hint: Turn this message off by running -hint: "git config advice.addIgnoredFile false" +hint: Disable this message with "git config advice.addIgnoredFile false" EOF cat >expect.out <<\EOF add 'track-this' diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 00c1f1aab1..5c4a89df5c 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -212,8 +212,7 @@ test_expect_success 'submodule add to .gitignored path fails' ' The following paths are ignored by one of your .gitignore files: submod hint: Use -f if you really want to add them. - hint: Turn this message off by running - hint: "git config advice.addIgnoredFile false" + hint: Disable this message with "git config advice.addIgnoredFile false" EOF # Does not use test_commit due to the ignore echo "*" > .gitignore && From patchwork Sat Mar 30 14:08:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13611585 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 4A40F2E407 for ; Sat, 30 Mar 2024 14:09:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711807750; cv=none; b=bHBoIFncsyRtKeyfu3HhHoFZ3YojLdx+dMO6l3CO2FfdpW/k5X3B3q1zcXIgjom84XWZeH4wKuHdHTiPUdXTcFTcs1/brKFPQSC4hGMDciDs7W2s0+c40rn7V8JY/Qvx8ud+y4CXZqBKgrPSd0gTsj4ngepOPT/EVQTwkK4Loz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711807750; c=relaxed/simple; bh=cWCNv6+CSGTw/HolqlG8XVfgIKjxfnyKGy3Edsqg8DE=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=NXUHr/r00zY6Y4mXtYgtiS5dMNlkzPXqdF+VFAl6EeD2sFqeYY+kQFy0h8dWoKUAgG7ZMgFRRqEPHNz+i90NWcvOpJfd1E8oTqGjZI0A+0NDufEwcFbrNxI1uwO4IFcepjCCqgbXn/3PSCMXC/h9lxbjabb1l5/kkoftnScR/B0= 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=HUdDm8Yb; arc=none smtp.client-ip=209.85.128.43 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="HUdDm8Yb" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4155bdc0bf5so1501605e9.1 for ; Sat, 30 Mar 2024 07:09:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711807746; x=1712412546; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=hjdu2rY57ENFkmm6x/igLaZ21xle0sgwarZuWC25ufA=; b=HUdDm8YbwL/+P5nn+5h7RSQqR6zIar4QWlqgRc/nozlsO0wis5LHaT3ceinThy5ZRI TfFaj50IV/x0QEA5LQAnRHIb4cTiId2HL9jvmQBw4WIaLBy+tnOwuV8hm6OsiI4ON2It AR1CE/dau6igcALSvdr8GAm7a9VdcCbnWl2lLyo0fPRQ2htd9XADwpVm/3FYvfj3BEuv CBnmSdGxqWj1ReMGzZMTjH4zzBBRi/rCMwyge5JUhXD2JkFTF3LZFwrCOGX5qaneZ1EX uzCpwYZxM9b3cVQDMgZcFQFsTHAudoQkq/c5l1bCeSkAXYJMPwGB299fUgmUA5bCEw3K IyTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711807746; x=1712412546; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hjdu2rY57ENFkmm6x/igLaZ21xle0sgwarZuWC25ufA=; b=j8QPU26Ncd8gJM1uK1eBHmp6k+45XS3b5v4ZljQMVZUu4IKZ5ZM987af5wG7wCGwku 9Qgkt37+uGJpMm3LIPk4K8dBfK7cBYHaFIKa7eVaTNRxcBiHvYiUj4Rrow07UUaUJ5Ms MOj7RKBIgwT7QMIseZaFYE9LPDErvbHbrXcAbKamWknHImY4D9iqk3Blua6qZHE33fK9 GseFECG4aWN5dMXns03HU1B5tklOAaTvcFiWThYRzC0oh7hm+c2S+9rACjz9KarrC1oV R2pOqEWipVUSewtxI2GkqWRi1dypvO71DEntX6EZ+/qWNoR7GjZeXybbKU4tDrSyAXMT rvlg== X-Gm-Message-State: AOJu0YzudBK0di0suSc9CwmEkRzraD9wKzOKF2UlL/rc/oZEpaDLoGdI 1yB+T2GKyQcKta8+Bff7eyUxbmnn0gnSPPD5NcSOn7EbuZh35KD4vvHT9P2z X-Google-Smtp-Source: AGHT+IH94aEkk++m8AlXDLuWN+TLvg/z3MQ0gACLKh6NOUsYJeyxtHI0uW0AZTqpuZkB9oL0t/gW3g== X-Received: by 2002:a05:600c:45c7:b0:414:204:df50 with SMTP id s7-20020a05600c45c700b004140204df50mr3604973wmo.4.1711807746435; Sat, 30 Mar 2024 07:09:06 -0700 (PDT) Received: from gmail.com (40.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.40]) by smtp.gmail.com with ESMTPSA id t12-20020a05600c450c00b004154853f778sm7436380wmo.48.2024.03.30.07.09.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Mar 2024 07:09:06 -0700 (PDT) Message-ID: <444bb0b2-781a-4eb7-a251-a1bbee2d87ce@gmail.com> Date: Sat, 30 Mar 2024 15:08:59 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 2/3] add: use advise_if_enabled for ADVICE_ADD_EMPTY_PATHSPEC From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <06c9b422-b22e-4310-ad5b-1686616ab860@gmail.com> <46fba030-d7aa-49d2-88fa-e506850f7b6a@gmail.com> Content-Language: en-US In-Reply-To: <46fba030-d7aa-49d2-88fa-e506850f7b6a@gmail.com> Since 93b0d86aaf (git-add: error out when given no arguments., 2006-12-20) we display a message when no arguments are given to "git add". Part of that message was converted to advice in bf66db37f1 (add: use advise function to display hints, 2020-01-07). Following the same line of reasoning as in the previous commit, it is sensible to use advise_if_enabled() here. Therefore, use advise_if_enabled() in builtin/add.c to show the ADVICE_ADD_EMPTY_PATHSPEC advice, and don't bother checking there the visibility of the advice or displaying the instruction on how to disable it. Also add a test for these messages, in order to detect a possible change in them. Signed-off-by: Rubén Justo --- builtin/add.c | 6 ++---- t/t3700-add.sh | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 8f148987f7..289adaaecf 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -438,10 +438,8 @@ int cmd_add(int argc, const char **argv, const char *prefix) if (require_pathspec && pathspec.nr == 0) { fprintf(stderr, _("Nothing specified, nothing added.\n")); - if (advice_enabled(ADVICE_ADD_EMPTY_PATHSPEC)) - advise( _("Maybe you wanted to say 'git add .'?\n" - "Turn this message off by running\n" - "\"git config advice.addEmptyPathspec false\"")); + advise_if_enabled(ADVICE_ADD_EMPTY_PATHSPEC, + _("Maybe you wanted to say 'git add .'?")); return 0; } diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 76c2c9e7b0..681081e0d5 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -28,6 +28,16 @@ test_expect_success 'Test of git add' ' touch foo && git add foo ' +test_expect_success 'Test with no pathspecs' ' + cat >expect <<-EOF && + Nothing specified, nothing added. + hint: Maybe you wanted to say ${SQ}git add .${SQ}? + hint: Disable this message with "git config advice.addEmptyPathspec false" + EOF + git add 2>actual && + test_cmp expect actual +' + test_expect_success 'Post-check that foo is in the index' ' git ls-files foo | grep foo ' From patchwork Sat Mar 30 14:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13611586 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 F10902C69C for ; Sat, 30 Mar 2024 14:09:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711807779; cv=none; b=nGJOyFxSpjxNXfB0tst1BXMg1fk7WT1bPQEc74qc94CDCewFT3wztq8Azxtck0CjHJUD2CM3Klp/IaKROvEQ8g8hU+qrIq4w348RR/aS0u31pwQCKDwbi+5bfBxgFkPr1/r1xBVFw3j0LW+C7amkvs1AVH4FovqK6f5xnEPfw1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711807779; c=relaxed/simple; bh=QQ/La8fuUc4SrmLmOPhfqg8sGUUCuVvZDXw44vxgsNY=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=KqVNWBd6uyQegr+OsMu/NkF9V7H3BEMbxPVPHkUTZfdf+Qor2Le7wY4iRBvkoZ7VslTZVsmKF6/urDsUJKVzWRpAVd1oqFolZCpYeQiYpMr5nEhYx7jHMY6fq/7s7ORu/vxy0c2BV1XmA11wVYhprbgivflijww3nMNHt/loPnw= 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=f0wx8DBs; arc=none smtp.client-ip=209.85.221.46 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="f0wx8DBs" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-341cce3e5f0so2444233f8f.1 for ; Sat, 30 Mar 2024 07:09:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711807776; x=1712412576; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=/Yk7M76DvN5C/1GY4kKAcS9oP/S7K2343ZiRx32ktMs=; b=f0wx8DBsqf8H/oUqjgrWex2JDdZtH2fADcR5sBDtB4zwJ9QonjPwJTWsYuOQU7DJrY aJtPy4mwggicKdgrOZ0rv68sUCa7vjzu3+V2g/2Lt3DPZ/vH8id5jCR20T5tYqm6qHu+ q/fqP4GcG17IS5bNBeP4E1wTBTuKEipnPXFWQl8BqxwC3o0M1Pf/1UDl4WOmTY6+J8kt 4H9+iHCOCFwmjRHRg8HCZH/W44llkM70jYbz3yhDRSqsAY0CQyQ5IZSU98cSEjg4uNYw 1TOfZep0i+Jfu7kW+rN164i1yM5nRqcYtNae3HndDxiVoECl+EMBQhfKXmGE1aM3RrvX iWuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711807776; x=1712412576; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/Yk7M76DvN5C/1GY4kKAcS9oP/S7K2343ZiRx32ktMs=; b=u7HpHwrBz9z0v3Cf4PlxbD02tqcUYCcykdbugPBSv+IuYVzVEFk8lKNgD+Gimo9F/S OarAdtV7PFRxhgnM4bLPNectM7/KuQGwZqdLUJGGSf2UYglRcADQ1dkb+pO7+vt5i1iE 83v5hGmvstDbZvTpYM7BdSxR/FhLKqBldn8sYhhSHzGt3Lb2awgJFyPa5cvRsnDAnDGv 4YMbhIzrWU1c/eTFdAWXnxGX1Tz1cycSREnNcarUdk9xdGCjadEfS6/QgNNmBICgnQlO j7vS1DhSZX+RaE6cxYseFCwOTPW5/iug6T8iTm9zlSUXFRD9sBThYrysri51FvRZQEt2 F1vA== X-Gm-Message-State: AOJu0YzzvD7f3Efyo+vp9Z+OTf1H6MUO4FFwKUzLq3n5t3OaR6XxXho4 9khy+zh/m7zg6wQHpEYQspD+rv7NsN1eriZXnnmwiNdvxv2vU5kLG+LzfbZq X-Google-Smtp-Source: AGHT+IH1MbnctAITcs+J8nT6oySwNKd4zGITRy9nRSva4SCiAwgU6z1zyhdGIRE0z5u+AwS0E8G+aQ== X-Received: by 2002:a05:6000:124f:b0:33e:69db:bf9e with SMTP id j15-20020a056000124f00b0033e69dbbf9emr3856989wrx.67.1711807776146; Sat, 30 Mar 2024 07:09:36 -0700 (PDT) Received: from gmail.com (40.red-88-14-45.dynamicip.rima-tde.net. [88.14.45.40]) by smtp.gmail.com with ESMTPSA id f10-20020a0560001b0a00b00341dbb4a3a7sm6498767wrz.86.2024.03.30.07.09.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Mar 2024 07:09:35 -0700 (PDT) Message-ID: Date: Sat, 30 Mar 2024 15:09:29 +0100 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2 3/3] add: use advise_if_enabled for ADVICE_ADD_EMBEDDED_REPO From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List Cc: Junio C Hamano References: <06c9b422-b22e-4310-ad5b-1686616ab860@gmail.com> <46fba030-d7aa-49d2-88fa-e506850f7b6a@gmail.com> Content-Language: en-US In-Reply-To: <46fba030-d7aa-49d2-88fa-e506850f7b6a@gmail.com> By following a similar reasoning as in previous commits, there are no reason why we should not use the advise_if_enabled() API to display the ADVICE_ADD_EMBEDDED_REPO advice. This advice was introduced in 532139940c (add: warn when adding an embedded repository, 2017-06-14). Some tests were included in the commit, but none is testing this advice. Which, note, we only want to display once per run. So, use the advise_if_enabled() machinery to show the ADVICE_ADD_EMBEDDED_REPO advice and include a test to notice any possible breakage. Signed-off-by: Junio C Hamano Signed-off-by: Rubén Justo --- builtin/add.c | 6 +++--- t/t3700-add.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index 289adaaecf..e97699d6b9 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -310,9 +310,9 @@ static void check_embedded_repo(const char *path) strbuf_strip_suffix(&name, "/"); warning(_("adding embedded git repository: %s"), name.buf); - if (!adviced_on_embedded_repo && - advice_enabled(ADVICE_ADD_EMBEDDED_REPO)) { - advise(embedded_advice, name.buf, name.buf); + if (!adviced_on_embedded_repo) { + advise_if_enabled(ADVICE_ADD_EMBEDDED_REPO, + embedded_advice, name.buf, name.buf); adviced_on_embedded_repo = 1; } diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 681081e0d5..839c904745 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -349,6 +349,40 @@ test_expect_success '"git add ." in empty repo' ' ) ' +test_expect_success '"git add" a embedded repository' ' + rm -fr outer && git init outer && + ( + cd outer && + for i in 1 2 + do + name=inner$i && + git init $name && + git -C $name commit --allow-empty -m $name || + return 1 + done && + git add . 2>actual && + cat >expect <<-EOF && + warning: adding embedded git repository: inner1 + hint: You${SQ}ve added another git repository inside your current repository. + hint: Clones of the outer repository will not contain the contents of + hint: the embedded repository and will not know how to obtain it. + hint: If you meant to add a submodule, use: + hint: + hint: git submodule add inner1 + hint: + hint: If you added this path by mistake, you can remove it from the + hint: index with: + hint: + hint: git rm --cached inner1 + hint: + hint: See "git help submodule" for more information. + hint: Disable this message with "git config advice.addEmbeddedRepo false" + warning: adding embedded git repository: inner2 + EOF + test_cmp expect actual + ) +' + test_expect_success 'error on a repository with no commits' ' rm -fr empty && git init empty &&