From patchwork Mon Mar 18 17:03:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13595643 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E6E954BFA for ; Mon, 18 Mar 2024 17:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781422; cv=none; b=b1vR5cjm1KsZBu9wXgTLhpRuK85vQOBWCxs2428kWAOWCJdmYOURp5dKfvWnllbHBS/cpAsT67vN4Qfc6UgnjvdeItDGNLLje5OoTashCuSsEV+ag8rimIVMXIcO5jYSee/qx8YLkwjEnTgwIKXLmjVDnpnk9+uh8fFXBlrKaDk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781422; c=relaxed/simple; bh=HafAkm914n1i3Ie3fCVRteaSBieutfMot2DB381B7n4=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GDYoVkOz1v9mUGR6isqLItq6LsLXHzTHiS+ENgA7his+wWSUbtu88TZ7tNHDw9tuycs3ngrwetdvUwZcsdAjYg5CbxFBWVA7pNJPEhnS6JCqA4oOYwm5JI8Le4a2t7RAn+5KcaZ41y1KxgB/AIzx5KQaLOyvE7hCxDVme+XO4eE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=cUTDsnvi; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="cUTDsnvi" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710781411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R1X3Hbgd+yE4oHYkBr0Ro8GXeDlXlZR9qhEb3EV/TRk=; b=cUTDsnviIye8bGe5wNefalN8fZdCJr9YbKcQ2leU5VVJltS3Heq8QlQI/YDx4G1hG86LdQ uKK4ARARGa/FbHcvKJXxl2IPUup6d1WNE6DbINgeTAHWyByJoKfRQoIC3CrNRrAadYBXU/ RN/KzvXtY/qguitZ7ks48TqPPKK/P+XkoPNmlr3JtzgUz4pXMm815uCJfcT4x0ivf2GDYy FuMmwhf4mDCoWPb7T+2cUmCl9akSERqqyG9zoxDKOy1asMTnIbAv6OHQkfvWKF7Tw2YXAH h+dS8Rj9cpz/vwgU8M/UskqNWMi7Rqz3oz2bztiouAnZL/i6cKT2rHITdRE8xg== To: git@vger.kernel.org Subject: [PATCH 1/5] grep: perform some minor code and comment cleanups Date: Mon, 18 Mar 2024 18:03:21 +0100 Message-Id: <96b81f3573d3f29bb97e77d623be0d53cf8085b0.1710781235.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Move some variable definitions around, and reflow one comment block, to make the code a bit neater after spotting those slightly unpolished areas. There are no functional changes to the source code. Signed-off-by: Dragan Simic --- builtin/grep.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 982bcfc4b1df..af89c8b5cb19 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -623,13 +623,13 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, struct tree_desc *tree, struct strbuf *base, int tn_len, int check_attr) { - struct repository *repo = opt->repo; - int hit = 0; + int hit = 0, name_base_len = 0; + int old_baselen = base->len; enum interesting match = entry_not_interesting; + struct repository *repo = opt->repo; struct name_entry entry; - int old_baselen = base->len; struct strbuf name = STRBUF_INIT; - int name_base_len = 0; + if (repo->submodule_prefix) { strbuf_addstr(&name, repo->submodule_prefix); name_base_len = name.len; @@ -890,19 +890,15 @@ static int pattern_callback(const struct option *opt, const char *arg, int cmd_grep(int argc, const char **argv, const char *prefix) { - int hit = 0; + int hit = 0, seen_dashdash = 0, use_index = 1; int cached = 0, untracked = 0, opt_exclude = -1; - int seen_dashdash = 0; int external_grep_allowed__ignored; + int i, dummy, allow_revs; const char *show_in_pager = NULL, *default_pager = "dummy"; struct grep_opt opt; struct object_array list = OBJECT_ARRAY_INIT; struct pathspec pathspec; struct string_list path_list = STRING_LIST_INIT_DUP; - int i; - int dummy; - int use_index = 1; - int allow_revs; struct option options[] = { OPT_BOOL(0, "cached", &cached, @@ -1059,9 +1055,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix) recurse_submodules = 0; /* - * skip a -- separator; we know it cannot be - * separating revisions from pathnames if - * we haven't even had any patterns yet + * skip a -- separator; we know it cannot be separating revisions + * from pathnames if we haven't even had any patterns yet */ if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) { argv++; From patchwork Mon Mar 18 17:03:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13595642 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E67354BF6 for ; Mon, 18 Mar 2024 17:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781422; cv=none; b=GTxiS7JeyJT+RGtI+k9PDUG5VIZr+rk43xCcS+gr7q/LqbhrbzjdhbLqfAoF9HSgrzco7D0LtuKj+s76HB4Upi5Xa1tApjfvB477TtErghrOREJj8yOUr1YhdgNUryUodoFyb1gwNXB3IGP/upzLGBo6p4IsSp1Vawwn8sYkvso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781422; c=relaxed/simple; bh=AHBowRYgbrg+h2/DufZ7l8Y156NoQa794a4zBYDqFco=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jXTnKuOoBB5kJm58YsTLUZWuInVYZI+mPt87qYiZ/wjSTACzRJ83HNOpyxl5RagmYlpLGiLBB+lplW1b1y7dPHjPmcioH1QzL13N1b+0pkaN04/QnOrMjrHF2c+4af8ikix+dTFJ6QbMwmvrjAzHQde3s7O8AAlKdSXgmE8ZvBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=W+ZOLZ4Y; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="W+ZOLZ4Y" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710781411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U5Tk76wSZvstfGUSWSZpIRxUUmpIAS1XYiR5Na3jlYc=; b=W+ZOLZ4YfhEdE1VWTnn67Rw5kIMiS3OorWTK2zVMNAd2J0GlP1XZhLxnyHXx8402eWRBbx DLIVVAEf+hPteL3iWDDekk7mNKeQqKaGuUWSSQRVmCuVKX9u8WjAUebjckzH3Z/Bb40CUw wxVh1MwHhDD2mqF87C/F2U8cYcpAzXNFijcqiR/ukOWcWtlsZLa9zyFJkJY8O+HAkP8Ssb YAkKMoSauA3xwKVx3ZsLlxev9hVFBm2m8STS8CNehS9wA/x+tANMRDqZ+LqiYUo4qDhHxT InUxpV25XLXctPjbw0KkdwQ1zwWYy/nMsuAyaM6RveRFtJ6h0KvOLaQgrDTUPw== To: git@vger.kernel.org Subject: [PATCH 2/5] grep docs: describe --recurse-submodules further and improve formatting a bit Date: Mon, 18 Mar 2024 18:03:22 +0100 Message-Id: <784912a8d9156fa00ddee218fd600254d7bab160.1710781235.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Clarify that --recurse-submodules cannot be used together with --untracked, and improve the formatting in a couple of places, to make it visually clear that those are the commands or the names of configuration options. Signed-off-by: Dragan Simic --- Documentation/config/grep.txt | 2 +- Documentation/git-grep.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index e521f20390ce..10041f27b0c8 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -24,5 +24,5 @@ grep.fullName:: If set to true, enable `--full-name` option by default. grep.fallbackToNoIndex:: - If set to true, fall back to git grep --no-index if git grep + If set to true, fall back to `git grep --no-index` if `git grep` is executed outside of a git repository. Defaults to false. diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 0d0103c780af..ade69f00ebdd 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -65,8 +65,8 @@ OPTIONS Recursively search in each submodule that is active and checked out in the repository. When used in combination with the option the prefix of all submodule output will be the name of - the parent project's object. This option has no effect - if `--no-index` is given. + the parent project's object. This option cannot be used together + with `--untracked`, and it has no effect if `--no-index` is specified. -a:: --text:: @@ -178,7 +178,7 @@ providing this option will cause it to die. Use \0 as the delimiter for pathnames in the output, and print them verbatim. Without this option, pathnames with "unusual" characters are quoted as explained for the configuration - variable core.quotePath (see linkgit:git-config[1]). + variable `core.quotePath` (see linkgit:git-config[1]). -o:: --only-matching:: From patchwork Mon Mar 18 17:03:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13595640 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E6AB54BF7 for ; Mon, 18 Mar 2024 17:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781421; cv=none; b=ll6krvTptaMsZTp1woaogA2ctlBYfog86IUNJqiZHBMPfvLc9ENbBufeVEWoQvE5OkHqKfQ58XGAO12tTonhSUC2K2z2XqkD5Kbp1puqhtBNtVp6FbPW1/aCbfkcgSR9HbfxqHDWy1L+9iaQDg0CL0xGgHDNUdc2BcGHBL4sjlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781421; c=relaxed/simple; bh=J80MmsINZwivdHM8PnHdDpgF2emOYX4ct5zqM6ppZUA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HODFNxunjh1mx4Z2rmGGoYQVhkzo9gj7v+MkTOgF1EhVjo6YGhR/oPbKhJGJj2AyOeoDtPPhfU2MMCwYfEZvAanFuwxydzS8ZG5/kh/sA5n5sIW1zSSuO/gKCuS1Xcv2hbIvIiFUO+AINm9xbf91cMCrs/eC4sW4lRglO+CF53E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=Cr65mK7q; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="Cr65mK7q" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710781411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YklGguCgfPO+/t9bR07jXoGH6HplMVGLdZqDw0OpJYg=; b=Cr65mK7qXeU+AX/mMuGFXjzlVsXFeMvKnLKVkqga0Cc2bnEpdizOcvyywp/s5W3Wq4Tcks ZYFwyRWB3mtxOD3+7t3YU+US9Zpm+JxbmHHLg/+zMFh22ajJU9YOywSxlnjAGwcMF4wG+R VgJkdzrY26HcP+LDBeJ23hYptuU4lptoZGgR0sEptBPaIFwNfqdZt5qtY9mGL6CVFA8Fhu cX1uqZ0vQFV3h539zUyx4nDCmKMeCx942wylH1bkUfuK/m81J6b1oNwR3WuuzO7i2+1aOL 5mNk9+8U9ZfuWOJwpWn1Cz5KCogHO0apfzW0uM4bVFE8LmMSyW/0GC4IR0KMEQ== To: git@vger.kernel.org Subject: [PATCH 3/5] grep docs: describe --no-index further Date: Mon, 18 Mar 2024 18:03:23 +0100 Message-Id: <3e6136028ca3327b027d57c46fb8155ef3c0d6c5.1710781235.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Describe the dependency between --no-index and either of the --cached and --untracked options, which cannot be used together. As part of that, shuffle a couple of the options, to make the documentation flow a bit better; it makes more sense to describe first the options that have something in common, and to after that describe an option that has some dependency on the already described options. Signed-off-by: Dragan Simic --- Documentation/git-grep.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index ade69f00ebdd..b377523381bb 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -28,7 +28,7 @@ SYNOPSIS [-f ] [-e] [--and|--or|--not|(|)|-e ...] [--recurse-submodules] [--parent-basename ] - [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | ...] + [ [--[no-]exclude-standard] [--cached | --untracked | --no-index] | ...] [--] [...] DESCRIPTION @@ -45,13 +45,15 @@ OPTIONS Instead of searching tracked files in the working tree, search blobs registered in the index file. ---no-index:: - Search files in the current directory that is not managed by Git. - --untracked:: In addition to searching in the tracked files in the working tree, search also in untracked files. +--no-index:: + Search files in the current directory that is not managed by Git. + This option cannot be used together with `--cached` or `--untracked`. + See also `grep.fallbackToNoIndex` in CONFIGURATION below. + --no-exclude-standard:: Also search in ignored files by not honoring the `.gitignore` mechanism. Only useful with `--untracked`. From patchwork Mon Mar 18 17:03:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13595641 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E62854BEF for ; Mon, 18 Mar 2024 17:03:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781422; cv=none; b=iFStG/CBpaXr1KnffX3g3dTe9U2u/yDPGvTm1Jyi886O58uQ6d3y7fTn9OuIofWdHm3VXBpGFOB+JgIR0gM96W71GrvYOpJA2YWrsxqQcNiOh+NH98qwM/+zOmIuyM/HWmD8nhDuDmZmQRHLFKZwDlMVywBjZh2C7Fl88sXXd3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781422; c=relaxed/simple; bh=6/zVtv66V3j437HgBq7a9Lt5mKObb3o67gOKzcYGR5k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PsKQW19TVxGfezVUnsqkX8/nPwSJYqzKiGQ5HhCAHiyR5ZJetMj8v1IQblNrmlyW1KIUHxkv2t2RYeAiAlhQ/mCJ6OB8jHoRarPeu/VzCkaDIIcphprU8k6V+668RPRLM3E0wE/ovDAB0Y8Wrsa4+iRv5E9RnIm9x0C8YJJ/DUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=Sr/bb/kz; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="Sr/bb/kz" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710781411; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S1clfhW8X25prny2BqppR/1LKCJ/ynoPHWdnYUhXx00=; b=Sr/bb/kzADHZqlcndPHbOx06K7+lQMY9rXrZ4VKspwg0Bghqqj9Tme5uiNBsprw/UmlyJF GSVFtyKixg1KTJBkdqjVEweaLHnEmsMoVMZd5JA8eDO0Fzu5eHIuu+kBPTqtTNuE0Hfun+ Pz+9GRA1CQOQzm97nGej+pj/vxpDaN6wmUsL9/0CVyebSEtDE9QkcJd2J1mGcOLfKKUPLf 0IS1oLJloZ/S5vuZ2H+Wi4pOH5SoTuLEye4WKok/n2KD0h3WoFxgapP7NOMOXj60eEG+R5 RdYNCRFcO1q+Fz0ioU+J7kvjzEcprdvscn6WsS2rgNnLsmrD/DRrdUiGibNg0w== To: git@vger.kernel.org Subject: [PATCH 4/5] grep: introduce new config option to include untracked files Date: Mon, 18 Mar 2024 18:03:24 +0100 Message-Id: <9f70eeb4f04a874a2036e1d8c61f3b7ec130663a.1710781235.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Add new configuration option grep.includeUntracked that enables --untracked option by default. This pretty much follows the logic established by the already existing configuration option grep.fallbackToNoIndex, while also respecting the dependencies of the --untracked option. Also add a few automated tests to the t7810, to cover the new configuration option by replicating the already existing tests for --untracked. Signed-off-by: Dragan Simic --- builtin/grep.c | 3 +++ t/t7810-grep.sh | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/builtin/grep.c b/builtin/grep.c index af89c8b5cb19..71d94126fb6e 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1041,6 +1041,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) the_repository->settings.command_requires_full_index = 0; } + if (use_index && !cached) + git_config_get_bool("grep.includeuntracked", &untracked); + if (use_index && !startup_info->have_repository) { int fallback = 0; git_config_get_bool("grep.fallbacktonoindex", &fallback); diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 875dcfd98f3a..de93936d585f 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1298,20 +1298,29 @@ test_expect_success 'inside git repository but with --no-index' ' git grep --untracked o >../actual.unignored && test_cmp ../expect.unignored ../actual.unignored && + git -c grep.includeUntracked=true grep o >../actual.unignored && + test_cmp ../expect.unignored ../actual.unignored && + git grep --no-index o >../actual.full && test_cmp ../expect.full ../actual.full && + git -c grep.includeUntracked=true grep --no-index o >../actual.full && + test_cmp ../expect.full ../actual.full && + git grep --no-index --exclude-standard o >../actual.unignored && test_cmp ../expect.unignored ../actual.unignored && cd sub && test_must_fail git grep o >../../actual.sub && test_must_be_empty ../../actual.sub && git grep --no-index o >../../actual.sub && test_cmp ../../expect.sub ../../actual.sub && git grep --untracked o >../../actual.sub && + test_cmp ../../expect.sub ../../actual.sub && + + git -c grep.includeUntracked=true grep o >../../actual.sub && test_cmp ../../expect.sub ../../actual.sub ) ' From patchwork Mon Mar 18 17:03:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Simic X-Patchwork-Id: 13595645 Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A26C455C27 for ; Mon, 18 Mar 2024 17:03:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781425; cv=none; b=UXmqAWS88ZjV0V4qb+J9MoFeCIoa0WyR5P1nnCYbzqaDCDX+27+lEYvHTkTYRGHX4M0nX7pyuQVxsF5fQOZ2Pz6bpb0qzyrwf7P1TmfgQUnfJQ3TtQ3iAh2il+w2ekenqd+PhQD2xTVFqoPzss7yrXFgxldr0zr1R4pmKFl35wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710781425; c=relaxed/simple; bh=+Nt9TIz1lSngdEfuWLTdgFFrbxiQIl+eUd/uAKaKTTU=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ou/RBMxdFSF/Agak5YbZXsNmQ1YC5KXnol+H0nYaE/IQfCS46DZfkJJ8VNAmiwCwFojQsmgAc+AUMSNuvarnbLfOXkvzpsO7McuVzaMkQ/gfk83jtILshfgnYPGSqxU+WzXFiJ6omQA3wUh2fUD+AfLtRS1da5rB0mTrYWBXxsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=bU4KqN0Z; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="bU4KqN0Z" From: Dragan Simic DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1710781412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IKyO4gerwcF0Z9g8rQ8oDKQEc077zWWTUptWOuap30g=; b=bU4KqN0Zy9wJGShfSydOiDhqJ9NNnRP/vBZggb+sfBDbjdSffRZhDOjMi6AgD1hKCNleGw FmmPtjXIDYfmQEyhJsKl2SOmx1W8whIMrQu75bAsM59caFUv+Fd8brd7d50JYalnezvS/w Yu74F0BqHd2Dv1BxZ3OZ6aRQF+n7ho1nJkB7QbwXGMAj8DjOmLgfWN1VXX0ouAhPqXBEq2 fP6hmgH8w5eQo4+ttpqGQIKaXmPKUqmYqqdfJyDDwD/rN0BqpxOI3vSKm0S3nAdSuRhF3v XmJLnXYyCbhWeI0HviHbFPcVspIHVWN+rDBqVDeSDLGJrz9ul6V5sV0GK7BpqQ== To: git@vger.kernel.org Subject: [PATCH 5/5] grep docs: describe new config option to include untracked files Date: Mon, 18 Mar 2024 18:03:25 +0100 Message-Id: <9ce006509306136bb2354006e3b14ceaf26d0d32.1710781235.git.dsimic@manjaro.org> In-Reply-To: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org Describe the new configuration option grep.includeUntracked, including the dependencies with the already existing options, and the conditions that make this option ignored, which allows other options to be used while the new option is enabled in one's git configuration file. Signed-off-by: Dragan Simic --- Documentation/config/grep.txt | 6 ++++++ Documentation/git-grep.txt | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/config/grep.txt b/Documentation/config/grep.txt index 10041f27b0c8..32f086997596 100644 --- a/Documentation/config/grep.txt +++ b/Documentation/config/grep.txt @@ -23,6 +23,12 @@ grep.threads:: grep.fullName:: If set to true, enable `--full-name` option by default. +grep.includeUntracked:: + If set to true, enable `--untracked` option by default, to search also + in untracked files, in addition to searching in the tracked files in the + working tree. If `--cached` or `--no-index` is specified, this option is + ignored. Also, it cannot be enabled together with `submodule.recurse`. + grep.fallbackToNoIndex:: If set to true, fall back to `git grep --no-index` if `git grep` is executed outside of a git repository. Defaults to false. diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index b377523381bb..af5f6572df16 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -47,7 +47,8 @@ OPTIONS --untracked:: In addition to searching in the tracked files in the working - tree, search also in untracked files. + tree, search also in untracked files. See also `grep.includeUntracked` + in CONFIGURATION below. --no-index:: Search files in the current directory that is not managed by Git.