@@ -623,83 +623,22 @@ static char *default_user_config(void)
623
623
return strbuf_detach (& buf , NULL );
624
624
}
625
625
626
- static struct option builtin_config_options [] = {
627
- OPT_GROUP (N_ ("Config file location" )),
628
- OPT_BOOL (0 , "global" , & use_global_config , N_ ("use global config file" )),
629
- OPT_BOOL (0 , "system" , & use_system_config , N_ ("use system config file" )),
630
- OPT_BOOL (0 , "local" , & use_local_config , N_ ("use repository config file" )),
631
- OPT_BOOL (0 , "worktree" , & use_worktree_config , N_ ("use per-worktree config file" )),
632
- OPT_STRING ('f' , "file" , & given_config_source .file , N_ ("file" ), N_ ("use given config file" )),
633
- OPT_STRING (0 , "blob" , & given_config_source .blob , N_ ("blob-id" ), N_ ("read config from given blob object" )),
634
- OPT_GROUP (N_ ("Action" )),
635
- OPT_CMDMODE (0 , "get" , & actions , N_ ("get value: name [<value-pattern>]" ), ACTION_GET ),
636
- OPT_CMDMODE (0 , "get-all" , & actions , N_ ("get all values: key [<value-pattern>]" ), ACTION_GET_ALL ),
637
- OPT_CMDMODE (0 , "get-regexp" , & actions , N_ ("get values for regexp: name-regex [<value-pattern>]" ), ACTION_GET_REGEXP ),
638
- OPT_CMDMODE (0 , "get-urlmatch" , & actions , N_ ("get value specific for the URL: section[.var] URL" ), ACTION_GET_URLMATCH ),
639
- OPT_CMDMODE (0 , "replace-all" , & actions , N_ ("replace all matching variables: name value [<value-pattern>]" ), ACTION_REPLACE_ALL ),
640
- OPT_CMDMODE (0 , "add" , & actions , N_ ("add a new variable: name value" ), ACTION_ADD ),
641
- OPT_CMDMODE (0 , "unset" , & actions , N_ ("remove a variable: name [<value-pattern>]" ), ACTION_UNSET ),
642
- OPT_CMDMODE (0 , "unset-all" , & actions , N_ ("remove all matches: name [<value-pattern>]" ), ACTION_UNSET_ALL ),
643
- OPT_CMDMODE (0 , "rename-section" , & actions , N_ ("rename section: old-name new-name" ), ACTION_RENAME_SECTION ),
644
- OPT_CMDMODE (0 , "remove-section" , & actions , N_ ("remove a section: name" ), ACTION_REMOVE_SECTION ),
645
- OPT_CMDMODE ('l' , "list" , & actions , N_ ("list all" ), ACTION_LIST ),
646
- OPT_CMDMODE ('e' , "edit" , & actions , N_ ("open an editor" ), ACTION_EDIT ),
647
- OPT_CMDMODE (0 , "get-color" , & actions , N_ ("find the color configured: slot [<default>]" ), ACTION_GET_COLOR ),
648
- OPT_CMDMODE (0 , "get-colorbool" , & actions , N_ ("find the color setting: slot [<stdout-is-tty>]" ), ACTION_GET_COLORBOOL ),
649
- OPT_GROUP (N_ ("Type" )),
650
- OPT_CALLBACK ('t' , "type" , & type , N_ ("type" ), N_ ("value is given this type" ), option_parse_type ),
651
- OPT_CALLBACK_VALUE (0 , "bool" , & type , N_ ("value is \"true\" or \"false\"" ), TYPE_BOOL ),
652
- OPT_CALLBACK_VALUE (0 , "int" , & type , N_ ("value is decimal number" ), TYPE_INT ),
653
- OPT_CALLBACK_VALUE (0 , "bool-or-int" , & type , N_ ("value is --bool or --int" ), TYPE_BOOL_OR_INT ),
654
- OPT_CALLBACK_VALUE (0 , "bool-or-str" , & type , N_ ("value is --bool or string" ), TYPE_BOOL_OR_STR ),
655
- OPT_CALLBACK_VALUE (0 , "path" , & type , N_ ("value is a path (file or directory name)" ), TYPE_PATH ),
656
- OPT_CALLBACK_VALUE (0 , "expiry-date" , & type , N_ ("value is an expiry date" ), TYPE_EXPIRY_DATE ),
657
- OPT_GROUP (N_ ("Other" )),
658
- OPT_BOOL ('z' , "null" , & end_nul , N_ ("terminate values with NUL byte" )),
659
- OPT_BOOL (0 , "name-only" , & omit_values , N_ ("show variable names only" )),
660
- OPT_BOOL (0 , "includes" , & respect_includes_opt , N_ ("respect include directives on lookup" )),
661
- OPT_BOOL (0 , "show-origin" , & show_origin , N_ ("show origin of config (file, standard input, blob, command line)" )),
662
- OPT_BOOL (0 , "show-scope" , & show_scope , N_ ("show scope of config (worktree, local, global, system, command)" )),
663
- OPT_STRING (0 , "default" , & default_value , N_ ("value" ), N_ ("with --get, use default value when missing entry" )),
664
- OPT_STRING (0 , "comment" , & comment_arg , N_ ("value" ), N_ ("human-readable comment string (# will be prepended as needed)" )),
665
- OPT_BOOL (0 , "fixed-value" , & fixed_value , N_ ("use string equality when comparing values to 'value-pattern'" )),
666
- OPT_END (),
667
- };
668
-
669
- static NORETURN void usage_builtin_config (void )
626
+ static void handle_config_location (const char * prefix )
670
627
{
671
- usage_with_options (builtin_config_usage , builtin_config_options );
672
- }
673
-
674
- int cmd_config (int argc , const char * * argv , const char * prefix )
675
- {
676
- int nongit = !startup_info -> have_repository ;
677
- char * value = NULL , * comment = NULL ;
678
- int flags = 0 ;
679
- int ret = 0 ;
680
- struct key_value_info default_kvi = KVI_INIT ;
681
-
682
- given_config_source .file = xstrdup_or_null (getenv (CONFIG_ENVIRONMENT ));
683
-
684
- argc = parse_options (argc , argv , prefix , builtin_config_options ,
685
- builtin_config_usage ,
686
- PARSE_OPT_STOP_AT_NON_OPTION );
687
-
688
628
if (use_global_config + use_system_config + use_local_config +
689
629
use_worktree_config +
690
630
!!given_config_source .file + !!given_config_source .blob > 1 ) {
691
631
error (_ ("only one config file at a time" ));
692
632
usage_builtin_config ();
693
633
}
694
634
695
- if (nongit ) {
635
+ if (! startup_info -> have_repository ) {
696
636
if (use_local_config )
697
637
die (_ ("--local can only be used inside a git repository" ));
698
638
if (given_config_source .blob )
699
639
die (_ ("--blob can only be used inside a git repository" ));
700
640
if (use_worktree_config )
701
641
die (_ ("--worktree can only be used inside a git repository" ));
702
-
703
642
}
704
643
705
644
if (given_config_source .file &&
@@ -753,10 +692,74 @@ int cmd_config(int argc, const char **argv, const char *prefix)
753
692
config_options .respect_includes = !given_config_source .file ;
754
693
else
755
694
config_options .respect_includes = respect_includes_opt ;
756
- if (! nongit ) {
695
+ if (startup_info -> have_repository ) {
757
696
config_options .commondir = get_git_common_dir ();
758
697
config_options .git_dir = get_git_dir ();
759
698
}
699
+ }
700
+
701
+ static struct option builtin_config_options [] = {
702
+ OPT_GROUP (N_ ("Config file location" )),
703
+ OPT_BOOL (0 , "global" , & use_global_config , N_ ("use global config file" )),
704
+ OPT_BOOL (0 , "system" , & use_system_config , N_ ("use system config file" )),
705
+ OPT_BOOL (0 , "local" , & use_local_config , N_ ("use repository config file" )),
706
+ OPT_BOOL (0 , "worktree" , & use_worktree_config , N_ ("use per-worktree config file" )),
707
+ OPT_STRING ('f' , "file" , & given_config_source .file , N_ ("file" ), N_ ("use given config file" )),
708
+ OPT_STRING (0 , "blob" , & given_config_source .blob , N_ ("blob-id" ), N_ ("read config from given blob object" )),
709
+ OPT_GROUP (N_ ("Action" )),
710
+ OPT_CMDMODE (0 , "get" , & actions , N_ ("get value: name [<value-pattern>]" ), ACTION_GET ),
711
+ OPT_CMDMODE (0 , "get-all" , & actions , N_ ("get all values: key [<value-pattern>]" ), ACTION_GET_ALL ),
712
+ OPT_CMDMODE (0 , "get-regexp" , & actions , N_ ("get values for regexp: name-regex [<value-pattern>]" ), ACTION_GET_REGEXP ),
713
+ OPT_CMDMODE (0 , "get-urlmatch" , & actions , N_ ("get value specific for the URL: section[.var] URL" ), ACTION_GET_URLMATCH ),
714
+ OPT_CMDMODE (0 , "replace-all" , & actions , N_ ("replace all matching variables: name value [<value-pattern>]" ), ACTION_REPLACE_ALL ),
715
+ OPT_CMDMODE (0 , "add" , & actions , N_ ("add a new variable: name value" ), ACTION_ADD ),
716
+ OPT_CMDMODE (0 , "unset" , & actions , N_ ("remove a variable: name [<value-pattern>]" ), ACTION_UNSET ),
717
+ OPT_CMDMODE (0 , "unset-all" , & actions , N_ ("remove all matches: name [<value-pattern>]" ), ACTION_UNSET_ALL ),
718
+ OPT_CMDMODE (0 , "rename-section" , & actions , N_ ("rename section: old-name new-name" ), ACTION_RENAME_SECTION ),
719
+ OPT_CMDMODE (0 , "remove-section" , & actions , N_ ("remove a section: name" ), ACTION_REMOVE_SECTION ),
720
+ OPT_CMDMODE ('l' , "list" , & actions , N_ ("list all" ), ACTION_LIST ),
721
+ OPT_CMDMODE ('e' , "edit" , & actions , N_ ("open an editor" ), ACTION_EDIT ),
722
+ OPT_CMDMODE (0 , "get-color" , & actions , N_ ("find the color configured: slot [<default>]" ), ACTION_GET_COLOR ),
723
+ OPT_CMDMODE (0 , "get-colorbool" , & actions , N_ ("find the color setting: slot [<stdout-is-tty>]" ), ACTION_GET_COLORBOOL ),
724
+ OPT_GROUP (N_ ("Type" )),
725
+ OPT_CALLBACK ('t' , "type" , & type , N_ ("type" ), N_ ("value is given this type" ), option_parse_type ),
726
+ OPT_CALLBACK_VALUE (0 , "bool" , & type , N_ ("value is \"true\" or \"false\"" ), TYPE_BOOL ),
727
+ OPT_CALLBACK_VALUE (0 , "int" , & type , N_ ("value is decimal number" ), TYPE_INT ),
728
+ OPT_CALLBACK_VALUE (0 , "bool-or-int" , & type , N_ ("value is --bool or --int" ), TYPE_BOOL_OR_INT ),
729
+ OPT_CALLBACK_VALUE (0 , "bool-or-str" , & type , N_ ("value is --bool or string" ), TYPE_BOOL_OR_STR ),
730
+ OPT_CALLBACK_VALUE (0 , "path" , & type , N_ ("value is a path (file or directory name)" ), TYPE_PATH ),
731
+ OPT_CALLBACK_VALUE (0 , "expiry-date" , & type , N_ ("value is an expiry date" ), TYPE_EXPIRY_DATE ),
732
+ OPT_GROUP (N_ ("Other" )),
733
+ OPT_BOOL ('z' , "null" , & end_nul , N_ ("terminate values with NUL byte" )),
734
+ OPT_BOOL (0 , "name-only" , & omit_values , N_ ("show variable names only" )),
735
+ OPT_BOOL (0 , "includes" , & respect_includes_opt , N_ ("respect include directives on lookup" )),
736
+ OPT_BOOL (0 , "show-origin" , & show_origin , N_ ("show origin of config (file, standard input, blob, command line)" )),
737
+ OPT_BOOL (0 , "show-scope" , & show_scope , N_ ("show scope of config (worktree, local, global, system, command)" )),
738
+ OPT_STRING (0 , "default" , & default_value , N_ ("value" ), N_ ("with --get, use default value when missing entry" )),
739
+ OPT_STRING (0 , "comment" , & comment_arg , N_ ("value" ), N_ ("human-readable comment string (# will be prepended as needed)" )),
740
+ OPT_BOOL (0 , "fixed-value" , & fixed_value , N_ ("use string equality when comparing values to 'value-pattern'" )),
741
+ OPT_END (),
742
+ };
743
+
744
+ static NORETURN void usage_builtin_config (void )
745
+ {
746
+ usage_with_options (builtin_config_usage , builtin_config_options );
747
+ }
748
+
749
+ int cmd_config (int argc , const char * * argv , const char * prefix )
750
+ {
751
+ char * value = NULL , * comment = NULL ;
752
+ int flags = 0 ;
753
+ int ret = 0 ;
754
+ struct key_value_info default_kvi = KVI_INIT ;
755
+
756
+ given_config_source .file = xstrdup_or_null (getenv (CONFIG_ENVIRONMENT ));
757
+
758
+ argc = parse_options (argc , argv , prefix , builtin_config_options ,
759
+ builtin_config_usage ,
760
+ PARSE_OPT_STOP_AT_NON_OPTION );
761
+
762
+ handle_config_location (prefix );
760
763
761
764
if (end_nul ) {
762
765
term = '\0' ;
@@ -858,7 +861,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
858
861
char * config_file ;
859
862
860
863
check_argc (argc , 0 , 0 );
861
- if (!given_config_source .file && nongit )
864
+ if (!given_config_source .file && ! startup_info -> have_repository )
862
865
die (_ ("not in a git directory" ));
863
866
if (given_config_source .use_stdin )
864
867
die (_ ("editing stdin is not supported" ));
0 commit comments