git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] [Outreachy] merge-ours: include parse-options

From
GGgeorge espinoza via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 28, 2019, 23:42 UTC
Message-ID
<8c088194f604eac3a6b00c48a7fddfdf807571fc.1572306149.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.425.git.1572306149.gitgitgadget@gmail.com>
From: george espinoza <gespinoz2019@gmail.com>

Teach this command which currently handles its own argv to use parse-options instead because parse-options helps make sure we handle user input like -h in a standardized way across the project. Also deleted the NO_PARSEOPT flag from git.c to coincide with the conversion of the structure in this command since merge-ours now uses parse-options and needed to update git.c accordingly.

Signed-off-by: george espinoza <gespinoz2019@gmail.com>
---
 builtin/merge-ours.c | 14 ++++++++++----
 git.c                |  2 +-
 2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/builtin/merge-ours.c b/builtin/merge-ours.c
index 4594507420..fb3674a384 100644
--- a/builtin/merge-ours.c
+++ b/builtin/merge-ours.c
@@ -11,14 +11,20 @@
 #include "git-compat-util.h"
 #include "builtin.h"
 #include "diff.h"
+#include "parse-options.h"
 
-static const char builtin_merge_ours_usage[] =
-	"git merge-ours <base>... -- HEAD <remote>...";
+static const char * const merge_ours_usage[] = {
+	N_("git merge-ours [<base>...] -- <head> <merge-head>..."),
+	NULL,
+};
 
 int cmd_merge_ours(int argc, const char **argv, const char *prefix)
 {
-	if (argc == 2 && !strcmp(argv[1], "-h"))
-		usage(builtin_merge_ours_usage);
+	struct option options[] = {
+		OPT_END()
+	};
+
+	argc = parse_options(argc, argv, prefix, options, merge_ours_usage, 0);
 
 	/*
 	 * The contents of the current index becomes the tree we
diff --git a/git.c b/git.c
index ce6ab0ece2..6aee0e9477 100644
--- a/git.c
+++ b/git.c
@@ -527,7 +527,7 @@ static struct cmd_struct commands[] = {
 	{ "merge-base", cmd_merge_base, RUN_SETUP },
 	{ "merge-file", cmd_merge_file, RUN_SETUP_GENTLY },
 	{ "merge-index", cmd_merge_index, RUN_SETUP | NO_PARSEOPT },
-	{ "merge-ours", cmd_merge_ours, RUN_SETUP | NO_PARSEOPT },
+	{ "merge-ours", cmd_merge_ours, RUN_SETUP },
 	{ "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
 	{ "merge-recursive-ours", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
 	{ "merge-recursive-theirs", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
-- 
gitgitgadget
Previous: George Espinoza via GitGitGadgetNext: Johannes Schindelin
Message 2 of 9 in “[Outreachy] merge-ours: include a parse-option”
  1. 0/1 [Outreachy] merge-ours: include a parse-optionGeorge Espinoza via GitGitGadget, Oct 28, 2019
  2. 1/1 [Outreachy] merge-ours: include parse-optionsgeorge espinoza via GitGitGadget, Oct 28, 2019
  3. Johannes SchindelinOct 29, 2019
  4. Emily ShafferOct 29, 2019
  5. George EspinozaOct 30, 2019
  6. Junio C HamanoOct 30, 2019
  7. George EspinozaOct 30, 2019
  8. Johannes SchindelinOct 30, 2019
  9. Junio C HamanoNov 2, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.