@@ -29,7 +29,6 @@ int advice_ignored_hook = 1;
29
29
int advice_waiting_for_editor = 1 ;
30
30
int advice_graft_file_deprecated = 1 ;
31
31
int advice_checkout_ambiguous_remote_branch_name = 1 ;
32
- int advice_nested_tag = 1 ;
33
32
int advice_submodule_alternate_error_strategy_die = 1 ;
34
33
int advice_add_ignored_file = 1 ;
35
34
int advice_add_empty_pathspec = 1 ;
@@ -82,7 +81,7 @@ static struct {
82
81
{ "sequencerInUse" , & advice_sequencer_in_use },
83
82
{ "implicitIdentity" , & advice_implicit_identity },
84
83
{ "detachedHead" , & advice_detached_head },
85
- { "setupStreamFailure " , & advice_set_upstream_failure },
84
+ { "setUpstreamFailure " , & advice_set_upstream_failure },
86
85
{ "objectNameWarning" , & advice_object_name_warning },
87
86
{ "amWorkDir" , & advice_amworkdir },
88
87
{ "rmHints" , & advice_rm_hints },
@@ -91,7 +90,6 @@ static struct {
91
90
{ "waitingForEditor" , & advice_waiting_for_editor },
92
91
{ "graftFileDeprecated" , & advice_graft_file_deprecated },
93
92
{ "checkoutAmbiguousRemoteBranchName" , & advice_checkout_ambiguous_remote_branch_name },
94
- { "nestedTag" , & advice_nested_tag },
95
93
{ "submoduleAlternateErrorStrategyDie" , & advice_submodule_alternate_error_strategy_die },
96
94
{ "addIgnoredFile" , & advice_add_ignored_file },
97
95
{ "addEmptyPathspec" , & advice_add_empty_pathspec },
@@ -100,15 +98,58 @@ static struct {
100
98
{ "pushNonFastForward" , & advice_push_update_rejected }
101
99
};
102
100
103
- void advise (const char * advice , ...)
101
+ static struct {
102
+ const char * key ;
103
+ int enabled ;
104
+ } advice_setting [] = {
105
+ [ADVICE_ADD_EMBEDDED_REPO ] = { "addEmbeddedRepo" , 1 },
106
+ [ADVICE_AM_WORK_DIR ] = { "amWorkDir" , 1 },
107
+ [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME ] = { "checkoutAmbiguousRemoteBranchName" , 1 },
108
+ [ADVICE_COMMIT_BEFORE_MERGE ] = { "commitBeforeMerge" , 1 },
109
+ [ADVICE_DETACHED_HEAD ] = { "detachedHead" , 1 },
110
+ [ADVICE_FETCH_SHOW_FORCED_UPDATES ] = { "fetchShowForcedUpdates" , 1 },
111
+ [ADVICE_GRAFT_FILE_DEPRECATED ] = { "graftFileDeprecated" , 1 },
112
+ [ADVICE_IGNORED_HOOK ] = { "ignoredHook" , 1 },
113
+ [ADVICE_IMPLICIT_IDENTITY ] = { "implicitIdentity" , 1 },
114
+ [ADVICE_NESTED_TAG ] = { "nestedTag" , 1 },
115
+ [ADVICE_OBJECT_NAME_WARNING ] = { "objectNameWarning" , 1 },
116
+ [ADVICE_PUSH_ALREADY_EXISTS ] = { "pushAlreadyExists" , 1 },
117
+ [ADVICE_PUSH_FETCH_FIRST ] = { "pushFetchFirst" , 1 },
118
+ [ADVICE_PUSH_NEEDS_FORCE ] = { "pushNeedsForce" , 1 },
119
+
120
+ /* make this an alias for backward compatibility */
121
+ [ADVICE_PUSH_UPDATE_REJECTED_ALIAS ] = { "pushNonFastForward" , 1 },
122
+
123
+ [ADVICE_PUSH_NON_FF_CURRENT ] = { "pushNonFFCurrent" , 1 },
124
+ [ADVICE_PUSH_NON_FF_MATCHING ] = { "pushNonFFMatching" , 1 },
125
+ [ADVICE_PUSH_UNQUALIFIED_REF_NAME ] = { "pushUnqualifiedRefName" , 1 },
126
+ [ADVICE_PUSH_UPDATE_REJECTED ] = { "pushUpdateRejected" , 1 },
127
+ [ADVICE_RESET_QUIET_WARNING ] = { "resetQuiet" , 1 },
128
+ [ADVICE_RESOLVE_CONFLICT ] = { "resolveConflict" , 1 },
129
+ [ADVICE_RM_HINTS ] = { "rmHints" , 1 },
130
+ [ADVICE_SEQUENCER_IN_USE ] = { "sequencerInUse" , 1 },
131
+ [ADVICE_SET_UPSTREAM_FAILURE ] = { "setUpstreamFailure" , 1 },
132
+ [ADVICE_STATUS_AHEAD_BEHIND_WARNING ] = { "statusAheadBehindWarning" , 1 },
133
+ [ADVICE_STATUS_HINTS ] = { "statusHints" , 1 },
134
+ [ADVICE_STATUS_U_OPTION ] = { "statusUoption" , 1 },
135
+ [ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE ] = { "submoduleAlternateErrorStrategyDie" , 1 },
136
+ [ADVICE_WAITING_FOR_EDITOR ] = { "waitingForEditor" , 1 },
137
+ };
138
+
139
+ static const char turn_off_instructions [] =
140
+ N_ ("\n"
141
+ "Disable this message with \"git config advice.%s false\"" );
142
+
143
+ static void vadvise (const char * advice , int display_instructions ,
144
+ const char * key , va_list params )
104
145
{
105
146
struct strbuf buf = STRBUF_INIT ;
106
- va_list params ;
107
147
const char * cp , * np ;
108
148
109
- va_start (params , advice );
110
149
strbuf_vaddf (& buf , advice , params );
111
- va_end (params );
150
+
151
+ if (display_instructions )
152
+ strbuf_addf (& buf , turn_off_instructions , key );
112
153
113
154
for (cp = buf .buf ; * cp ; cp = np ) {
114
155
np = strchrnul (cp , '\n' );
@@ -122,6 +163,37 @@ void advise(const char *advice, ...)
122
163
strbuf_release (& buf );
123
164
}
124
165
166
+ void advise (const char * advice , ...)
167
+ {
168
+ va_list params ;
169
+ va_start (params , advice );
170
+ vadvise (advice , 0 , "" , params );
171
+ va_end (params );
172
+ }
173
+
174
+ int advice_enabled (enum advice_type type )
175
+ {
176
+ switch (type ) {
177
+ case ADVICE_PUSH_UPDATE_REJECTED :
178
+ return advice_setting [ADVICE_PUSH_UPDATE_REJECTED ].enabled &&
179
+ advice_setting [ADVICE_PUSH_UPDATE_REJECTED_ALIAS ].enabled ;
180
+ default :
181
+ return advice_setting [type ].enabled ;
182
+ }
183
+ }
184
+
185
+ void advise_if_enabled (enum advice_type type , const char * advice , ...)
186
+ {
187
+ va_list params ;
188
+
189
+ if (!advice_enabled (type ))
190
+ return ;
191
+
192
+ va_start (params , advice );
193
+ vadvise (advice , 1 , advice_setting [type ].key , params );
194
+ va_end (params );
195
+ }
196
+
125
197
int git_default_advice_config (const char * var , const char * value )
126
198
{
127
199
const char * k , * slot_name ;
@@ -148,6 +220,13 @@ int git_default_advice_config(const char *var, const char *value)
148
220
if (strcasecmp (k , advice_config [i ].name ))
149
221
continue ;
150
222
* advice_config [i ].preference = git_config_bool (var , value );
223
+ break ;
224
+ }
225
+
226
+ for (i = 0 ; i < ARRAY_SIZE (advice_setting ); i ++ ) {
227
+ if (strcasecmp (k , advice_setting [i ].key ))
228
+ continue ;
229
+ advice_setting [i ].enabled = git_config_bool (var , value );
151
230
return 0 ;
152
231
}
153
232
@@ -158,8 +237,8 @@ void list_config_advices(struct string_list *list, const char *prefix)
158
237
{
159
238
int i ;
160
239
161
- for (i = 0 ; i < ARRAY_SIZE (advice_config ); i ++ )
162
- list_config_item (list , prefix , advice_config [i ].name );
240
+ for (i = 0 ; i < ARRAY_SIZE (advice_setting ); i ++ )
241
+ list_config_item (list , prefix , advice_setting [i ].key );
163
242
}
164
243
165
244
int error_resolve_conflict (const char * me )
0 commit comments