Either --global, --system, or --file can be used, but not any
combination.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
builtin-config.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 302846e..876eb0e 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -315,6 +315,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
+ if (use_global_config + use_system_config + !!given_config_file > 1) {
+ error("only one config file at a time.");
+ usage_with_options(builtin_config_usage, builtin_config_options);
+ }
+
if (use_global_config) {
char *home = getenv("HOME");
if (home) {
--
1.6.1.3
--
Only --bool, --int, or --bool-or-int can be used, but not any
combination of them.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
builtin-config.c | 32 ++++++++++++++++++++------------
1 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 876eb0e..c2a30f2 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -19,11 +19,10 @@ static int seen;
static char delim = '=';
static char key_delim = ' ';
static char term = '\n';
-static enum { T_RAW, T_INT, T_BOOL, T_BOOL_OR_INT } type = T_RAW;
static int use_global_config, use_system_config;
static const char *given_config_file;
-static int actions;
+static int actions, types;
static const char *get_color_slot, *get_colorbool_slot;
static int end_null;
@@ -43,6 +42,10 @@ static int end_null;
#define ACTION_GET_COLOR (1<<13)
#define ACTION_GET_COLORBOOL (1<<14)
+#define TYPE_BOOL (1<<0)
+#define TYPE_INT (1<<1)
+#define TYPE_BOOL_OR_INT (1<<2)
+
static struct option builtin_config_options[] = {
OPT_GROUP("Config file location"),
OPT_BOOLEAN(0, "global", &use_global_config, "use global config file"),
@@ -63,9 +66,9 @@ static struct option builtin_config_options[] = {
OPT_STRING(0, "get-color", &get_color_slot, "slot", "find the color configured: [default]"),
OPT_STRING(0, "get-colorbool", &get_colorbool_slot, "slot", "find the color setting: [stdout-is-tty]"),
OPT_GROUP("Type"),
- OPT_SET_INT(0, "bool", &type, "value is \"true\" or \"false\"", T_BOOL),
- OPT_SET_INT(0, "int", &type, "value is decimal number", T_INT),
- OPT_SET_INT(0, "bool-or-int", &type, NULL, T_BOOL_OR_INT),
+ OPT_BIT(0, "bool", &types, "value is \"true\" or \"false\"", TYPE_BOOL),
+ OPT_BIT(0, "int", &types, "value is decimal number", TYPE_INT),
+ OPT_BIT(0, "bool-or-int", &types, NULL, TYPE_BOOL_OR_INT),
OPT_GROUP("Other"),
OPT_BOOLEAN('z', "null", &end_null, "terminate values with NUL byte"),
OPT_END(),
@@ -109,11 +112,11 @@ static int ...As suggested by Johannes Schindelin.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
builtin-config.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index c2a30f2..8045926 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -373,6 +373,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
}
if (actions == ACTION_LIST) {
+ check_argc(argc, 0, 0);
if (git_config(show_all_config, NULL) < 0) {
if (config_exclusive_filename)
die("unable to read config file %s: %s",
@@ -382,6 +383,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
}
}
else if (actions == ACTION_EDIT) {
+ check_argc(argc, 0, 0);
git_config(git_default_config, NULL);
launch_editor(config_exclusive_filename ?
config_exclusive_filename : git_path("config"),
--
1.6.1.3
--
Doing so would be incoherent since --get-color would pick a color slot
and ignore the variable type option (e.g. --bool), and the type would
require a variable name.
Suggested by Junio C Hamano.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
builtin-config.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/builtin-config.c b/builtin-config.c
index 8045926..9930568 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -359,6 +359,11 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)
if (get_colorbool_slot)
actions |= ACTION_GET_COLORBOOL;
+ if ((get_color_slot || get_colorbool_slot) && types) {
+ error("--get-color and variable type are incoherent");
+ usage_with_options(builtin_config_usage, builtin_config_options);
+ }
+
if (HAS_MULTI_BITS(actions)) {
error("only one action at a time.");
usage_with_options(builtin_config_usage, builtin_config_options);
--
1.6.1.