🌐 AI搜索 & 代理 主页
blob: 4dc5cf10a8533b1bfc3bd1483e91df115aa8f868 [file] [log] [blame]
Jeff King75194432009-09-09 11:38:581#include "cache.h"
2
Chris Rorvick11845642012-12-03 03:27:503int advice_push_update_rejected = 1;
Christopher Tiwaldf25950f2012-03-20 04:31:334int advice_push_non_ff_current = 1;
Christopher Tiwaldf25950f2012-03-20 04:31:335int advice_push_non_ff_matching = 1;
Chris Rorvickb4505682012-12-03 03:27:516int advice_push_already_exists = 1;
Junio C Hamano75e5c0d2013-01-23 21:55:307int advice_push_fetch_first = 1;
8int advice_push_needs_force = 1;
Jeff Kingedf563f2009-09-09 11:43:039int advice_status_hints = 1;
Nguyễn Thái Ngọc Duy6a38ef22013-03-13 12:59:1610int advice_status_u_option = 1;
Matthieu Moy4c371f92009-11-22 22:26:1711int advice_commit_before_merge = 1;
Matthieu Moyd38a30d2010-01-12 09:54:4412int advice_resolve_conflict = 1;
Jeff Kingb706fcf2010-01-13 20:17:0813int advice_implicit_identity = 1;
Junio C Hamano13be3e32010-01-30 06:03:2414int advice_detached_head = 1;
Jeff Kingcaa20362013-04-02 19:05:1215int advice_set_upstream_failure = 1;
Nguyễn Thái Ngọc Duy798c35f2013-05-29 12:12:4216int advice_object_name_warning = 1;
Mathieu Lienard--Mayor7e309442013-06-12 08:06:4417int advice_rm_hints = 1;
Jeff King75194432009-09-09 11:38:5818
19static struct {
20 const char *name;
21 int *preference;
22} advice_config[] = {
Chris Rorvick11845642012-12-03 03:27:5023 { "pushupdaterejected", &advice_push_update_rejected },
Christopher Tiwaldf25950f2012-03-20 04:31:3324 { "pushnonffcurrent", &advice_push_non_ff_current },
Christopher Tiwaldf25950f2012-03-20 04:31:3325 { "pushnonffmatching", &advice_push_non_ff_matching },
Chris Rorvickb4505682012-12-03 03:27:5126 { "pushalreadyexists", &advice_push_already_exists },
Junio C Hamano75e5c0d2013-01-23 21:55:3027 { "pushfetchfirst", &advice_push_fetch_first },
28 { "pushneedsforce", &advice_push_needs_force },
Jeff Kingedf563f2009-09-09 11:43:0329 { "statushints", &advice_status_hints },
Nguyễn Thái Ngọc Duy6a38ef22013-03-13 12:59:1630 { "statusuoption", &advice_status_u_option },
Matthieu Moy4c371f92009-11-22 22:26:1731 { "commitbeforemerge", &advice_commit_before_merge },
Matthieu Moyd38a30d2010-01-12 09:54:4432 { "resolveconflict", &advice_resolve_conflict },
Jeff Kingb706fcf2010-01-13 20:17:0833 { "implicitidentity", &advice_implicit_identity },
Junio C Hamano13be3e32010-01-30 06:03:2434 { "detachedhead", &advice_detached_head },
Jeff Kingcaa20362013-04-02 19:05:1235 { "setupstreamfailure", &advice_set_upstream_failure },
Thomas Rast8dc84fd2013-07-31 20:23:3136 { "objectnamewarning", &advice_object_name_warning },
Mathieu Lienard--Mayor7e309442013-06-12 08:06:4437 { "rmhints", &advice_rm_hints },
Chris Rorvick11845642012-12-03 03:27:5038
39 /* make this an alias for backward compatibility */
40 { "pushnonfastforward", &advice_push_update_rejected }
Jeff King75194432009-09-09 11:38:5841};
42
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5943void advise(const char *advice, ...)
44{
Junio C Hamano23cb5bf2011-12-22 19:21:2645 struct strbuf buf = STRBUF_INIT;
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5946 va_list params;
Junio C Hamano23cb5bf2011-12-22 19:21:2647 const char *cp, *np;
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5948
49 va_start(params, advice);
Jeff King447b99c2012-07-23 18:48:5750 strbuf_vaddf(&buf, advice, params);
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5951 va_end(params);
Junio C Hamano23cb5bf2011-12-22 19:21:2652
53 for (cp = buf.buf; *cp; cp = np) {
54 np = strchrnul(cp, '\n');
55 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
56 if (*np)
57 np++;
58 }
59 strbuf_release(&buf);
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5960}
61
Jeff King75194432009-09-09 11:38:5862int git_default_advice_config(const char *var, const char *value)
63{
Jeff Kingcf4fff52014-06-18 19:44:1964 const char *k;
Jeff King75194432009-09-09 11:38:5865 int i;
66
Jeff Kingcf4fff52014-06-18 19:44:1967 if (!skip_prefix(var, "advice.", &k))
68 return 0;
69
Jeff King75194432009-09-09 11:38:5870 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
71 if (strcmp(k, advice_config[i].name))
72 continue;
73 *advice_config[i].preference = git_config_bool(var, value);
74 return 0;
75 }
76
77 return 0;
78}
Matthieu Moyd38a30d2010-01-12 09:54:4479
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5980int error_resolve_conflict(const char *me)
Matthieu Moyd38a30d2010-01-12 09:54:4481{
Jeff Kingd7952162014-06-03 07:23:4982 error("%s is not possible because you have unmerged files.", me);
Junio C Hamano23cb5bf2011-12-22 19:21:2683 if (advice_resolve_conflict)
Matthieu Moyd38a30d2010-01-12 09:54:4484 /*
85 * Message used both when 'git commit' fails and when
86 * other commands doing a merge do.
87 */
Jeff Kingc057b242014-06-03 07:17:1788 advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
Matthieu Moy91e70e02014-08-28 09:46:5889 "as appropriate to mark resolution and make a commit."));
Ramkumar Ramachandra38ef61c2011-08-04 10:38:5990 return -1;
91}
92
93void NORETURN die_resolve_conflict(const char *me)
94{
95 error_resolve_conflict(me);
96 die("Exiting because of an unresolved conflict.");
Matthieu Moyd38a30d2010-01-12 09:54:4497}
Nguyễn Thái Ngọc Duy28570932012-01-16 09:46:1698
Paul Tan4a4cf9e2015-06-18 10:54:0499void NORETURN die_conclude_merge(void)
100{
101 error(_("You have not concluded your merge (MERGE_HEAD exists)."));
102 if (advice_resolve_conflict)
Alex Henrieb7447672015-10-02 04:25:33103 advise(_("Please, commit your changes before merging."));
Paul Tan4a4cf9e2015-06-18 10:54:04104 die(_("Exiting because of unfinished merge."));
105}
106
Nguyễn Thái Ngọc Duy28570932012-01-16 09:46:16107void detach_advice(const char *new_name)
108{
109 const char fmt[] =
110 "Note: checking out '%s'.\n\n"
111 "You are in 'detached HEAD' state. You can look around, make experimental\n"
112 "changes and commit them, and you can discard any commits you make in this\n"
113 "state without impacting any branches by performing another checkout.\n\n"
114 "If you want to create a new branch to retain commits you create, you may\n"
115 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
Alex Henrie9c9b4f22015-01-13 07:44:47116 " git checkout -b <new-branch-name>\n\n";
Nguyễn Thái Ngọc Duy28570932012-01-16 09:46:16117
118 fprintf(stderr, fmt, new_name);
119}