5 int advice_push_update_rejected
= 1;
6 int advice_push_non_ff_current
= 1;
7 int advice_push_non_ff_matching
= 1;
8 int advice_push_already_exists
= 1;
9 int advice_push_fetch_first
= 1;
10 int advice_push_needs_force
= 1;
11 int advice_status_hints
= 1;
12 int advice_status_u_option
= 1;
13 int advice_commit_before_merge
= 1;
14 int advice_resolve_conflict
= 1;
15 int advice_implicit_identity
= 1;
16 int advice_detached_head
= 1;
17 int advice_set_upstream_failure
= 1;
18 int advice_object_name_warning
= 1;
19 int advice_rm_hints
= 1;
20 int advice_add_embedded_repo
= 1;
21 int advice_ignored_hook
= 1;
22 int advice_waiting_for_editor
= 1;
23 int advice_graft_file_deprecated
= 1;
25 static int advice_use_color
= -1;
26 static char advice_colors
[][COLOR_MAXLEN
] = {
28 GIT_COLOR_YELLOW
, /* HINT */
32 ADVICE_COLOR_RESET
= 0,
33 ADVICE_COLOR_HINT
= 1,
36 static int parse_advise_color_slot(const char *slot
)
38 if (!strcasecmp(slot
, "reset"))
39 return ADVICE_COLOR_RESET
;
40 if (!strcasecmp(slot
, "hint"))
41 return ADVICE_COLOR_HINT
;
45 static const char *advise_get_color(enum color_advice ix
)
47 if (want_color_stderr(advice_use_color
))
48 return advice_colors
[ix
];
56 { "pushupdaterejected", &advice_push_update_rejected
},
57 { "pushnonffcurrent", &advice_push_non_ff_current
},
58 { "pushnonffmatching", &advice_push_non_ff_matching
},
59 { "pushalreadyexists", &advice_push_already_exists
},
60 { "pushfetchfirst", &advice_push_fetch_first
},
61 { "pushneedsforce", &advice_push_needs_force
},
62 { "statushints", &advice_status_hints
},
63 { "statusuoption", &advice_status_u_option
},
64 { "commitbeforemerge", &advice_commit_before_merge
},
65 { "resolveconflict", &advice_resolve_conflict
},
66 { "implicitidentity", &advice_implicit_identity
},
67 { "detachedhead", &advice_detached_head
},
68 { "setupstreamfailure", &advice_set_upstream_failure
},
69 { "objectnamewarning", &advice_object_name_warning
},
70 { "rmhints", &advice_rm_hints
},
71 { "addembeddedrepo", &advice_add_embedded_repo
},
72 { "ignoredhook", &advice_ignored_hook
},
73 { "waitingforeditor", &advice_waiting_for_editor
},
74 { "graftfiledeprecated", &advice_graft_file_deprecated
},
76 /* make this an alias for backward compatibility */
77 { "pushnonfastforward", &advice_push_update_rejected
}
80 void advise(const char *advice
, ...)
82 struct strbuf buf
= STRBUF_INIT
;
86 va_start(params
, advice
);
87 strbuf_vaddf(&buf
, advice
, params
);
90 for (cp
= buf
.buf
; *cp
; cp
= np
) {
91 np
= strchrnul(cp
, '\n');
92 fprintf(stderr
, _("%shint: %.*s%s\n"),
93 advise_get_color(ADVICE_COLOR_HINT
),
95 advise_get_color(ADVICE_COLOR_RESET
));
102 int git_default_advice_config(const char *var
, const char *value
)
104 const char *k
, *slot_name
;
107 if (!strcmp(var
, "color.advice")) {
108 advice_use_color
= git_config_colorbool(var
, value
);
112 if (skip_prefix(var
, "color.advice.", &slot_name
)) {
113 int slot
= parse_advise_color_slot(slot_name
);
117 return config_error_nonbool(var
);
118 return color_parse(value
, advice_colors
[slot
]);
121 if (!skip_prefix(var
, "advice.", &k
))
124 for (i
= 0; i
< ARRAY_SIZE(advice_config
); i
++) {
125 if (strcmp(k
, advice_config
[i
].name
))
127 *advice_config
[i
].preference
= git_config_bool(var
, value
);
134 int error_resolve_conflict(const char *me
)
136 if (!strcmp(me
, "cherry-pick"))
137 error(_("Cherry-picking is not possible because you have unmerged files."));
138 else if (!strcmp(me
, "commit"))
139 error(_("Committing is not possible because you have unmerged files."));
140 else if (!strcmp(me
, "merge"))
141 error(_("Merging is not possible because you have unmerged files."));
142 else if (!strcmp(me
, "pull"))
143 error(_("Pulling is not possible because you have unmerged files."));
144 else if (!strcmp(me
, "revert"))
145 error(_("Reverting is not possible because you have unmerged files."));
147 error(_("It is not possible to %s because you have unmerged files."),
150 if (advice_resolve_conflict
)
152 * Message used both when 'git commit' fails and when
153 * other commands doing a merge do.
155 advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
156 "as appropriate to mark resolution and make a commit."));
160 void NORETURN
die_resolve_conflict(const char *me
)
162 error_resolve_conflict(me
);
163 die(_("Exiting because of an unresolved conflict."));
166 void NORETURN
die_conclude_merge(void)
168 error(_("You have not concluded your merge (MERGE_HEAD exists)."));
169 if (advice_resolve_conflict
)
170 advise(_("Please, commit your changes before merging."));
171 die(_("Exiting because of unfinished merge."));
174 void detach_advice(const char *new_name
)
177 _("Note: checking out '%s'.\n\n"
178 "You are in 'detached HEAD' state. You can look around, make experimental\n"
179 "changes and commit them, and you can discard any commits you make in this\n"
180 "state without impacting any branches by performing another checkout.\n\n"
181 "If you want to create a new branch to retain commits you create, you may\n"
182 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
183 " git checkout -b <new-branch-name>\n\n");
185 fprintf(stderr
, fmt
, new_name
);