add-patch: add diff.context command line overrides
This patch compliments the previous commit, where builtins that use add-patch infrastructure now respect diff.context and diff.interHunkContext file configurations. In particular, this patch helps users who don't want to set persistent context configurations or just want a way to override them on a one-time basis, by allowing the relevant builtins to accept corresponding command line options that override the file configurations. This mimics commands such as diff and log, which allow for both context file configuration and command line overrides. Signed-off-by: Leon Michalak <leonmichalak6@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
2b0a2db2c0
commit
2b3ae04011
@@ -19,6 +19,7 @@
|
||||
#include "environment.h"
|
||||
#include "diff.h"
|
||||
#include "commit.h"
|
||||
#include "add-interactive.h"
|
||||
#include "gettext.h"
|
||||
#include "revision.h"
|
||||
#include "wt-status.h"
|
||||
@@ -122,6 +123,7 @@ static const char *edit_message, *use_message;
|
||||
static char *fixup_message, *fixup_commit, *squash_message;
|
||||
static const char *fixup_prefix;
|
||||
static int all, also, interactive, patch_interactive, only, amend, signoff;
|
||||
static struct add_p_opt add_p_opt = ADD_P_OPT_INIT;
|
||||
static int edit_flag = -1; /* unspecified */
|
||||
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
|
||||
static int config_commit_verbose = -1; /* unspecified */
|
||||
@@ -354,6 +356,11 @@ static const char *prepare_index(const char **argv, const char *prefix,
|
||||
const char *ret;
|
||||
char *path = NULL;
|
||||
|
||||
if (add_p_opt.context < -1)
|
||||
die(_("'%s' cannot be negative"), "--unified");
|
||||
if (add_p_opt.interhunkcontext < -1)
|
||||
die(_("'%s' cannot be negative"), "--inter-hunk-context");
|
||||
|
||||
if (is_status)
|
||||
refresh_flags |= REFRESH_UNMERGED;
|
||||
parse_pathspec(&pathspec, 0,
|
||||
@@ -400,7 +407,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
|
||||
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
|
||||
setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1);
|
||||
|
||||
if (interactive_add(the_repository, argv, prefix, patch_interactive) != 0)
|
||||
if (interactive_add(the_repository, argv, prefix, patch_interactive, &add_p_opt) != 0)
|
||||
die(_("interactive add failed"));
|
||||
|
||||
the_repository->index_file = old_repo_index_file;
|
||||
@@ -424,6 +431,11 @@ static const char *prepare_index(const char **argv, const char *prefix,
|
||||
commit_style = COMMIT_NORMAL;
|
||||
ret = get_lock_file_path(&index_lock);
|
||||
goto out;
|
||||
} else {
|
||||
if (add_p_opt.context != -1)
|
||||
die(_("the option '%s' requires '%s'"), "--unified", "--interactive/--patch");
|
||||
if (add_p_opt.interhunkcontext != -1)
|
||||
die(_("the option '%s' requires '%s'"), "--inter-hunk-context", "--interactive/--patch");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1722,6 +1734,8 @@ int cmd_commit(int argc,
|
||||
OPT_BOOL('i', "include", &also, N_("add specified files to index for commit")),
|
||||
OPT_BOOL(0, "interactive", &interactive, N_("interactively add files")),
|
||||
OPT_BOOL('p', "patch", &patch_interactive, N_("interactively add changes")),
|
||||
OPT_DIFF_UNIFIED(&add_p_opt.context),
|
||||
OPT_DIFF_INTERHUNK_CONTEXT(&add_p_opt.interhunkcontext),
|
||||
OPT_BOOL('o', "only", &only, N_("commit only specified files")),
|
||||
OPT_BOOL('n', "no-verify", &no_verify, N_("bypass pre-commit and commit-msg hooks")),
|
||||
OPT_BOOL(0, "dry-run", &dry_run, N_("show what would be committed")),
|
||||
|
||||
Reference in New Issue
Block a user