From patchwork Mon Mar 18 15:51:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ghanshyam Thakkar X-Patchwork-Id: 13595503 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.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 668105339A for ; Mon, 18 Mar 2024 15:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710777273; cv=none; b=dL61e23v7j1i2IdKDlvvZgpT4tjrN3b0O/BzpTSp2LalRXJBxCgr5xZiHM6rxyQ+5ZURR7tLJ6uIqAkcIo9XQ7D8gMtE9E6b/T4L1lejhZLUmnHkFM7g1As3Ft5SZMGogMrA7cXk+bUCZafhaV4j51MwLm6TqigRTz0V+HA3z2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710777273; c=relaxed/simple; bh=zDBC1O+GhHUKzkX7xS7NIiFPEKd1hH6MQdY1V/cUKkQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h73YyvOl2gzgmQaoDIwSbCwTvpUHsjRWQICwPFKHrie1XE9kQ8PFQNbQCWDNxKB5BNWn4Gx9oGYDrkX4+C1WIPp20AwwIEg/Ze7tfaQz5qmDlc2fH6dHsKv47cl4G8XDYKt7D55Xclrb/3m3Pj1zzpwZgIZ6P8Tqvw9UpBufYTs= 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=RvTxXeRu; arc=none smtp.client-ip=209.85.215.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="RvTxXeRu" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-5c66b093b86so4082583a12.0 for ; Mon, 18 Mar 2024 08:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710777271; x=1711382071; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2gobrQGTh14bRBFGQihQN8cFPl8UJzNCKtlUxNI/f3g=; b=RvTxXeRuclFHjspoCtUOiPeYONxJ5h3+SRabkd8xxyCdVCUKHUKw8c9q1muGsFqw/t tnyMQm9lhVJP9Ota5z5aUOcb/3Tttt1GDMRpcM1/NdwVAaJXIQnSqVViwos7c4PPFiIu mJnd9gFzxbIoYoflP53j8Rqcp6ldhNuNMHO2hdwICVbhqwfnenQuzvTlrcHM6qjzQj3S PlgQ4BOPt3tJWCZlY/9y50+9Qc9z4p2/lc9njz1h1U/l64zdBQuA70efcvAHvtXK0/05 Bw089lGE+eTnqI5go4fhb2nrWsvyF93jTS9sJTIXrlGiOiBjPAEDrDFvv6pAjK1K/rq8 lhww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710777271; x=1711382071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2gobrQGTh14bRBFGQihQN8cFPl8UJzNCKtlUxNI/f3g=; b=Ok8Sk6yep04rUxH9sCZBHrDejciA50cMRUOlKaZZad7LPpsy5ka52cDPfS2cIWg0P9 ExkD5SdaTOUPQX8OqtPeGon1fwNTpq/2IoTrW85JzzTYEYJTB3NhYCe7U1xl20jAG4EL RT/Qxtwirv5X9R4xLJlY1B40SywzM1OLWg+ZtJ+2NQxJBAd3qfpMiwenk+q3WHfJhpKN ThyQF++cinR0OzdXdtxCwTl+Bt/5ClT5LxzaFZi0V779EpjIJ2kd0Gy1rprqpyBptEDk sQz3wSge5ImeikWJPa7ppJu1V90yAm70CsXhuEyZlQRI7BM84lTCoJaMKLlXRuZh0TTi EjvQ== X-Gm-Message-State: AOJu0YzInrbh2Ocd3fiHulRY/x0pGowyajL5kRYSmFXLGH8gg+AFlDxP MxhcZnPzbu72wgkSsK3vUKp5nt6z9NzfiWHdOHeTaf3FXbJF4PbsZn9bF4rK X-Google-Smtp-Source: AGHT+IHBKYxTlvR2CXln9LphV/B0r7Zuj8UosroAPLE4nEU5OjMsX1zxx5hR6tZKMeObAmpNPF16BQ== X-Received: by 2002:a17:90b:34c:b0:29e:89b:9446 with SMTP id fh12-20020a17090b034c00b0029e089b9446mr47528pjb.1.1710777271288; Mon, 18 Mar 2024 08:54:31 -0700 (PDT) Received: from localhost.localdomain ([2402:a00:401:a99b:f188:2dd3:d960:a8ab]) by smtp.gmail.com with ESMTPSA id gd1-20020a17090b0fc100b0029beec8e86csm7844922pjb.36.2024.03.18.08.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 08:54:30 -0700 (PDT) From: Ghanshyam Thakkar To: git@vger.kernel.org Cc: Ghanshyam Thakkar Subject: [PATCH 1/2] builtin/commit: error out when passing untracked path with -i Date: Mon, 18 Mar 2024 21:21:59 +0530 Message-ID: <20240318155219.494206-4-shyamthakkar001@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318155219.494206-2-shyamthakkar001@gmail.com> References: <20240318155219.494206-2-shyamthakkar001@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently when we provide a pathspec which does not match any tracked path alongside --include, we do not error like without --include. If there is something staged, it will commit the staged changes and ignore the pathspec which does not match any tracked path. And if nothing is staged, it will print the status. Exit code is 0 in both cases (unlike without --include). This was also described in the TODO comment before the relevant testcase. Fix this by matching the pathspec against index and report error if any. And amend the relevant testcase and remove the TODO comment. As this matches the pathspec against index, we need to also make sure that the sparse index is expanded before matching the pathspec. A side-effect of this is removal of --include related lines from the testcase which checks if the sparse-index is expanded or not in t1092. Signed-off-by: Ghanshyam Thakkar --- [RFC]: I am still unsure about the removal of --include related lines from the testcase which checks whether the index is expanded or not from t1092. Will separating it into a separate testcase of its own and marking that to expect failure be better? builtin/commit.c | 15 +++++++++++++++ t/t1092-sparse-checkout-compatibility.sh | 4 ---- t/t7501-commit-basic-functionality.sh | 16 +--------------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/builtin/commit.c b/builtin/commit.c index a91197245f..f8f5909673 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -441,6 +441,21 @@ static const char *prepare_index(const char **argv, const char *prefix, * (B) on failure, rollback the real index. */ if (all || (also && pathspec.nr)) { + if (!all) { + int i, ret; + char *ps_matched = xcalloc(pathspec.nr, 1); + + /* TODO: audit for interaction with sparse-index. */ + ensure_full_index(&the_index); + for (i = 0; i < the_index.cache_nr; i++) + ce_path_match(&the_index, the_index.cache[i], + &pathspec, ps_matched); + + ret = report_path_error(ps_matched, &pathspec); + free(ps_matched); + if (ret) + exit(1); + } repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR); add_files_to_cache(the_repository, also ? prefix : NULL, diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 2f1ae5fd3b..b55c81d4f7 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1418,10 +1418,6 @@ test_expect_success 'sparse-index is not expanded' ' ensure_not_expanded commit --allow-empty -m empty && echo >>sparse-index/a && ensure_not_expanded commit -a -m a && - echo >>sparse-index/a && - ensure_not_expanded commit --include a -m a && - echo >>sparse-index/deep/deeper1/a && - ensure_not_expanded commit --include deep/deeper1/a -m deeper && ensure_not_expanded checkout rename-out-to-out && ensure_not_expanded checkout - && ensure_not_expanded switch rename-out-to-out && diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index bced44a0fc..cc12f99f11 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -101,22 +101,8 @@ test_expect_success 'fail to commit untracked file (even with --include/--only)' test_must_fail git commit --only -m "baz" baz 2>err && test_grep -e "$error" err && - # TODO: as for --include, the below command will fail because - # nothing is staged. If something was staged, it would not fail - # even though the provided pathspec does not match any tracked - # path. (However, the untracked paths that match the pathspec are - # not committed and only the staged changes get committed.) - # In either cases, no error is returned to stderr like in (--only - # and without --only/--include) cases. In a similar manner, - # "git add -u baz" also does not error out. - # - # Therefore, the below test is just to document the current behavior - # and is not an endorsement to the current behavior, and we may - # want to fix this. And when that happens, this test should be - # updated accordingly. - test_must_fail git commit --include -m "baz" baz 2>err && - test_must_be_empty err + test_grep -e "$error" err ' test_expect_success 'setup: non-initial commit' ' From patchwork Mon Mar 18 15:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ghanshyam Thakkar X-Patchwork-Id: 13595504 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.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 68926535BA for ; Mon, 18 Mar 2024 15:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710777283; cv=none; b=ILh1v2Jkjc7JO3bcjCDjU2lswpyg7bW2ezUdgD5Mk7nTyo3XJ8lGR4Ddw7L6zX/CARC0Jg/dKLDMEJGFWev6pIERyHMr0K4CFW0SYboZUXqyXfulJnbGdxyZCGEr+PsBuyBkBor3xc3ksGEGS3JweJlNChjLm1ZelHfbXVlPc2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710777283; c=relaxed/simple; bh=FmjSm7ZK3qPwkNrrzNKuLIaLhM3BhZPGjOVa+wOulb4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MTYHn30T6wOCi/c2q9pHzhO5SLchPsa9JIbextRz/M4KjXITE590+z3FiQy7A0DU/M3soV5LCJHBY7P1uOXgM/0ImTLIacKleZietI1YGRresg1Jq8k7/E+Qfb48T+SVWOIXX7qwpXidRtU7sanWx9vgsNkAfzAfT9FSvL53eXs= 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=W0zFt/hf; arc=none smtp.client-ip=209.85.216.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="W0zFt/hf" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-29dd91f3aaeso2996092a91.3 for ; Mon, 18 Mar 2024 08:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710777281; x=1711382081; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/6Uo5gRiOdS5veOBIOXl8WmoDbtFK98mTYCEGqQcRps=; b=W0zFt/hf9dG7fBxq6dqky2McIJ1yA99ubwz1jUEM62tmU/67n7RjOixIVEp8SFCz53 H5v8IlKhZXKb0T0SuPR9lEuSaTK9RuaWtzT3DZInknw5oZqmBmBgkYMKSst4KS3PJgBA OKeCXQqr+aAvEtB/2YRzrfaikuoOdFOg2HJTW7pCbW8juv93Nc7RWz3RMz9ZC1p8dyGp t8Mw6mBte/jy+Vsb93429vLfdJ7VlwBjzNvl+H3fUwOz7f9794rTCqQGcxsLmUcb1dQ4 GB8TqOW+SnnMpTuzWtBmraMa9JeCDhmAdcc1pV0OrCRsL654JvZPs+YqwHEi+EspYY9Y vPzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710777281; x=1711382081; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/6Uo5gRiOdS5veOBIOXl8WmoDbtFK98mTYCEGqQcRps=; b=iajkQZN78DkHtmXZLx9KqxJrmOy+gtlHYnXprzwFFFj/bi9x8wY+t7e22cSUvhIhoo Y849n5D9z0U7r2Gcz9BQmUB+X3WVln+0bq/U7SL0gMgJvq+215k3uC/fS+Wa80W+8uKh yeh31gHyBohrwS0oIFP+IbFTNuXPLTC35csdVqn/gGJpFk/iqnTp5ezVo6JgMWQpyQE/ FIrEA4+pvSyqJwTKAYbhAenhppm35uw3r4+rDvJeWQCc0Appv+6fXjsh9mEzZRcoyT4m PHxEF5KMKklrNFPcGEnh2msw8q5syFo8G+fhDa8whwnKdGo22uIv/hriMziePUMxS4jY 6PyQ== X-Gm-Message-State: AOJu0Yy2juLywG6PpiYVnlTNxCw5BpT9PRPBcYp7CmUGEgb+mMvbiY9/ 9tl+vqbZVUg8cJadBIMMjnGMPx5fzoX7VRz5WzHPjDlFAUxOzjc6lQ7AsiI9 X-Google-Smtp-Source: AGHT+IELXNh3SxchSyaekE8ruAQo0hZN2n2ddUtXGNsNZLYsruvGIN6NiC1edJrBmAr9MbAp88XMIw== X-Received: by 2002:a17:90a:7785:b0:29e:2b58:ba55 with SMTP id v5-20020a17090a778500b0029e2b58ba55mr2302pjk.20.1710777280764; Mon, 18 Mar 2024 08:54:40 -0700 (PDT) Received: from localhost.localdomain ([2402:a00:401:a99b:f188:2dd3:d960:a8ab]) by smtp.gmail.com with ESMTPSA id gd1-20020a17090b0fc100b0029beec8e86csm7844922pjb.36.2024.03.18.08.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 08:54:40 -0700 (PDT) From: Ghanshyam Thakkar To: git@vger.kernel.org Cc: Ghanshyam Thakkar Subject: [PATCH 2/2] builtin/add: error out when passing untracked path with -u Date: Mon, 18 Mar 2024 21:22:01 +0530 Message-ID: <20240318155219.494206-6-shyamthakkar001@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318155219.494206-2-shyamthakkar001@gmail.com> References: <20240318155219.494206-2-shyamthakkar001@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently when we pass a pathspec which does not match any tracked path along side --update, it silently succeeds, unlike without --update. As --update only touches known paths, match the pathspec against the index and error out when no match found. And ensure that the index is fully expanded before matching the pathspec. Also add a testcase to check for the error. Signed-off-by: Ghanshyam Thakkar --- builtin/add.c | 16 ++++++++++++++++ t/t2200-add-update.sh | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/builtin/add.c b/builtin/add.c index 393c10cbcf..7ec5ea4a3e 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -24,6 +24,7 @@ #include "strvec.h" #include "submodule.h" #include "add-interactive.h" +#include "sparse-index.h" static const char * const builtin_add_usage[] = { N_("git add [] [--] ..."), @@ -536,6 +537,21 @@ int cmd_add(int argc, const char **argv, const char *prefix) } } + if (take_worktree_changes && pathspec.nr) { + int i, ret; + char *ps_matched = xcalloc(pathspec.nr, 1); + + /* TODO: audit for interaction with sparse-index. */ + ensure_full_index(&the_index); + for (i = 0; i < the_index.cache_nr; i++) + ce_path_match(&the_index, the_index.cache[i], + &pathspec, ps_matched); + + ret = report_path_error(ps_matched, &pathspec); + free(ps_matched); + if (ret) + exit(1); + } if (only_match_skip_worktree.nr) { advise_on_updating_sparse_paths(&only_match_skip_worktree); diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index c01492f33f..f6a9615d1b 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -65,6 +65,11 @@ test_expect_success 'update did not touch untracked files' ' test_must_be_empty out ' +test_expect_success 'error out when given untracked path' ' + test_must_fail git add -u dir2/other 2>err && + test_grep -e "error: pathspec .dir2/other. did not match any file(s) known to git" err +' + test_expect_success 'cache tree has not been corrupted' ' git ls-files -s | From patchwork Fri Mar 29 20:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ghanshyam Thakkar X-Patchwork-Id: 13611079 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 08E8C13AD1E for ; Fri, 29 Mar 2024 21:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711746172; cv=none; b=gK8gav5ibHowWlvZD9CuIwdB6dGTVvWthSU3JZrl6k1tsx7a1Eh8yu6T+VAPKnYyqX0/9tT9TOFstZ9jj65PdX6UdMwjX2Lb4yU/po8nR0XoCo2y3a6jLOaHpCuxuubkDSG/VARMNDO0KXZXFnaFum33KRxHUvtCCLwuvWonz7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711746172; c=relaxed/simple; bh=CDo+f/jeqcnFWm+SosfSCI3kwzPXsV1gbWfGwMVcWMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bnHLx6iZXC1kN4FGI2waJZldYSBFCkjqm5EUyCZcKtwECx8lGodi/w4tv6qiHmy16U9D/im9UkxKx7Xrkr/f6XWG6hD9yrNKXaELkqYhfWQzbdo6T0uZhX7j3v7wgiyK5zR/I0h482SF2I48dC/rOB80heBm8H+QIiTM43t5030= 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=KQWSOtuM; arc=none smtp.client-ip=209.85.214.181 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="KQWSOtuM" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1e0f2798cd8so20964615ad.3 for ; Fri, 29 Mar 2024 14:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711746170; x=1712350970; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fdXv6zFewObycaDa3BGUf1Ki/nEP6niYmGnn7nsxykA=; b=KQWSOtuMUi4UXmlrMzv/zLZa3Ih/h9UwmNIBFs2VOXO6appp/t3JwlZ/nEUyk8YWg1 VY7nVZTZzcHszfZ1rG8k8SvSgG2Ay7M+vu4Mzi9Xh8X0EU80m9jFZE9rq+6/s75g+3ot VGC1vEEVbfE9lpioUKEOhGg4WU8RKH9p6BX+K4xvwIMVq9/gulM+ke47/2j9E0MAhV76 Gw/dL3pYEb6Z4uNkpmUHMa7IquHbil3xSm7kNzhnXH2Gd1jbBxS7htFX+snq22MfGMap Q7Hgu0XwFwqO5TgWCVRkWfU+XN/slZiXj3dSmN0FiFqRw5uxVAi146/SFmIakmjd6ZB3 aWXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711746170; x=1712350970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fdXv6zFewObycaDa3BGUf1Ki/nEP6niYmGnn7nsxykA=; b=Dkz6ytZ16pmibkqqBR0zaI76FTOALorbwTAL4i8LXZtug4QKVTp2uF/vu0+9Km93gu 6CIW1Nyxp7cpKfpEGSWYAjDR41EQEEl9tOmnrs2qR6LrbEecFwjpdedxYEcg+JjenaUD 4z55U648JYIST4ESgzDN6yUJct7QL52KRkl7fnhMHZUVqIhtaMueFXrBNo+iqwup8hi+ OTdfn5ztpR8JBDa/0QuRo4aFkW3DZGjJbiqT0HXJ8//s7o0PLQKbab2wF5tm6aoZtKSX s4/C7o+P1zhn+/ctO0H17DvoQQSudSYHn6x5nBPR2y17cFi+eKWId4bQTTs9vGoVnp7g NFTw== X-Gm-Message-State: AOJu0YwgkWg2yV0qPrOrHgSpamCl6a3fEJZ42T7JykuWnFNsQ5he1Wvi bgCu1mbboJVzJFOkzBmgHi+Ody97JbCvXnqvtnvSGP3tu5E2Rkc08KYghRybtnc= X-Google-Smtp-Source: AGHT+IFnnyzauu5fcBzhxYK9newmBBajP4YVEq9LSVz3vIMkyY1Z2jjjENyTCp+4l7byicrTt0knNA== X-Received: by 2002:a17:902:ecd2:b0:1dd:a3d4:9545 with SMTP id a18-20020a170902ecd200b001dda3d49545mr4203499plh.54.1711746169726; Fri, 29 Mar 2024 14:02:49 -0700 (PDT) Received: from localhost.localdomain ([2402:a00:401:a99b:f188:2dd3:d960:a8ab]) by smtp.gmail.com with ESMTPSA id i10-20020a17090332ca00b001e020a47fe9sm3875327plr.261.2024.03.29.14.02.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 14:02:49 -0700 (PDT) From: Ghanshyam Thakkar To: git@vger.kernel.org Cc: gitster@pobox.com, Ghanshyam Thakkar Subject: [PATCH v2 3/3] builtin/add: error out when passing untracked path with -u Date: Sat, 30 Mar 2024 02:26:21 +0530 Message-ID: <20240329205649.1483032-5-shyamthakkar001@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240318155219.494206-2-shyamthakkar001@gmail.com> References: <20240318155219.494206-2-shyamthakkar001@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When passing untracked path with -u option, it silently succeeds. There is no error message and the exit code is zero. This is inconsistent with other instances of git commands where the expected argument is a known path. In those other instances, we error out when the path is not known. Therefore, fix this by passing a character array to add_files_to_cache() to collect the pathspec matching information and report the error if a pathspec does not match any cache entry. Also add a testcase to cover this scenario. Signed-off-by: Ghanshyam Thakkar --- builtin/add.c | 9 ++++++++- t/t2200-add-update.sh | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/builtin/add.c b/builtin/add.c index ffe5fd8d44..650432bb13 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -370,6 +370,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) int add_new_files; int require_pathspec; char *seen = NULL; + char *ps_matched = NULL; struct lock_file lock_file = LOCK_INIT; git_config(add_config, NULL); @@ -547,15 +548,20 @@ int cmd_add(int argc, const char **argv, const char *prefix) string_list_clear(&only_match_skip_worktree, 0); } + begin_odb_transaction(); + ps_matched = xcalloc(pathspec.nr, 1); if (add_renormalize) exit_status |= renormalize_tracked_files(&pathspec, flags); else exit_status |= add_files_to_cache(the_repository, prefix, - &pathspec, NULL, + &pathspec, ps_matched, include_sparse, flags); + if (take_worktree_changes) + exit_status |= report_path_error(ps_matched, &pathspec); + if (add_new_files) exit_status |= add_files(&dir, flags); @@ -568,6 +574,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) COMMIT_LOCK | SKIP_IF_UNCHANGED)) die(_("unable to write new index file")); + free(ps_matched); dir_clear(&dir); clear_pathspec(&pathspec); return exit_status; diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index c01492f33f..7cba325f08 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -65,6 +65,12 @@ test_expect_success 'update did not touch untracked files' ' test_must_be_empty out ' +test_expect_success 'error out when passing untracked path' ' + echo content >baz && + test_must_fail git add -u baz 2>err && + test_grep -e "error: pathspec .baz. did not match any file(s) known to git" err +' + test_expect_success 'cache tree has not been corrupted' ' git ls-files -s |