public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Siddharth Shrimali <r.siddharth.shrimali@gmail•com>
To: git@vger•kernel.org
Cc: gitster@pobox•com, christian.couder@gmail•com, toon@iotcl•com,
	jn.avila@free•fr, r.siddharth.shrimali@gmail•com
Subject: [PATCH 2/2] builtin/add: use die_for_required_opt() helper
Date: Wed,  3 Jun 2026 16:40:44 +0530	[thread overview]
Message-ID: <20260603111044.39116-3-r.siddharth.shrimali@gmail.com> (raw)
In-Reply-To: <20260603111044.39116-1-r.siddharth.shrimali@gmail.com>

Clean up manual option dependency checks by replacing explicit conditional
blocks with the newly introduced die_for_required_opt() helper function.

Specifically, simplify the prerequisite check logic for both
'--ignore-missing' (which requires '--dry-run') and '--pathspec-file-nul'
(which requires '--pathspec-from-file').

Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail•com>
---
 builtin/add.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index c859f66519..a5c91c6dcf 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -441,8 +441,7 @@ int cmd_add(int argc,
 	if (addremove && take_worktree_changes)
 		die(_("options '%s' and '%s' cannot be used together"), "-A", "-u");
 
-	if (!show_only && ignore_missing)
-		die(_("the option '%s' requires '%s'"), "--ignore-missing", "--dry-run");
+	die_for_required_opt(ignore_missing, "--ignore-missing", show_only, "--dry-run");
 
 	if (chmod_arg && ((chmod_arg[0] != '-' && chmod_arg[0] != '+') ||
 			  chmod_arg[1] != 'x' || chmod_arg[2]))
@@ -462,6 +461,8 @@ int cmd_add(int argc,
 		       PATHSPEC_SYMLINK_LEADING_PATH,
 		       prefix, argv);
 
+	die_for_required_opt(pathspec_file_nul, "--pathspec-file-nul",
+				!!pathspec_from_file, "--pathspec-from-file");
 	if (pathspec_from_file) {
 		if (pathspec.nr)
 			die(_("'%s' and pathspec arguments cannot be used together"), "--pathspec-from-file");
@@ -470,8 +471,6 @@ int cmd_add(int argc,
 				    PATHSPEC_PREFER_FULL |
 				    PATHSPEC_SYMLINK_LEADING_PATH,
 				    prefix, pathspec_from_file, pathspec_file_nul);
-	} else if (pathspec_file_nul) {
-		die(_("the option '%s' requires '%s'"), "--pathspec-file-nul", "--pathspec-from-file");
 	}
 
 	if (require_pathspec && pathspec.nr == 0) {
-- 
2.54.0


  parent reply	other threads:[~2026-06-03 11:11 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03 11:10 [PATCH 0/2] parse-options: introduce die_for_required_opt() helper Siddharth Shrimali
2026-06-03 11:10 ` [PATCH 1/2] parse-options: introduce die_for_required_opt() Siddharth Shrimali
2026-06-03 19:48   ` Jean-Noël AVILA
2026-06-04  8:00     ` Christian Couder
2026-06-04  8:10   ` Christian Couder
2026-06-03 11:10 ` Siddharth Shrimali [this message]
2026-06-04  8:27   ` [PATCH 2/2] builtin/add: use die_for_required_opt() helper Christian Couder
2026-06-04  7:45 ` [PATCH 0/2] parse-options: introduce " Christian Couder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260603111044.39116-3-r.siddharth.shrimali@gmail.com \
    --to=r.siddharth.shrimali@gmail$(echo .)com \
    --cc=christian.couder@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=jn.avila@free$(echo .)fr \
    --cc=toon@iotcl$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox