]>
Commit | Line | Data |
---|---|---|
75194438 | 1 | #include "cache.h" |
b2141fc1 | 2 | #include "config.h" |
75194438 | 3 | |
1184564e | 4 | int advice_push_update_rejected = 1; |
f25950f3 | 5 | int advice_push_non_ff_current = 1; |
f25950f3 | 6 | int advice_push_non_ff_matching = 1; |
b4505682 | 7 | int advice_push_already_exists = 1; |
75e5c0dc JH |
8 | int advice_push_fetch_first = 1; |
9 | int advice_push_needs_force = 1; | |
edf563fb | 10 | int advice_status_hints = 1; |
6a38ef2c | 11 | int advice_status_u_option = 1; |
4c371f91 | 12 | int advice_commit_before_merge = 1; |
d38a30df | 13 | int advice_resolve_conflict = 1; |
b706fcfe | 14 | int advice_implicit_identity = 1; |
13be3e31 | 15 | int advice_detached_head = 1; |
caa2036b | 16 | int advice_set_upstream_failure = 1; |
798c35fc | 17 | int advice_object_name_warning = 1; |
7e309446 | 18 | int advice_rm_hints = 1; |
53213994 | 19 | int advice_add_embedded_repo = 1; |
f805a00a | 20 | int advice_ignored_hook = 1; |
75194438 JK |
21 | |
22 | static struct { | |
23 | const char *name; | |
24 | int *preference; | |
25 | } advice_config[] = { | |
1184564e | 26 | { "pushupdaterejected", &advice_push_update_rejected }, |
f25950f3 | 27 | { "pushnonffcurrent", &advice_push_non_ff_current }, |
f25950f3 | 28 | { "pushnonffmatching", &advice_push_non_ff_matching }, |
b4505682 | 29 | { "pushalreadyexists", &advice_push_already_exists }, |
75e5c0dc JH |
30 | { "pushfetchfirst", &advice_push_fetch_first }, |
31 | { "pushneedsforce", &advice_push_needs_force }, | |
edf563fb | 32 | { "statushints", &advice_status_hints }, |
6a38ef2c | 33 | { "statusuoption", &advice_status_u_option }, |
4c371f91 | 34 | { "commitbeforemerge", &advice_commit_before_merge }, |
d38a30df | 35 | { "resolveconflict", &advice_resolve_conflict }, |
b706fcfe | 36 | { "implicitidentity", &advice_implicit_identity }, |
13be3e31 | 37 | { "detachedhead", &advice_detached_head }, |
caa2036b | 38 | { "setupstreamfailure", &advice_set_upstream_failure }, |
8dc84fdc | 39 | { "objectnamewarning", &advice_object_name_warning }, |
7e309446 | 40 | { "rmhints", &advice_rm_hints }, |
53213994 | 41 | { "addembeddedrepo", &advice_add_embedded_repo }, |
f805a00a | 42 | { "ignoredhook", &advice_ignored_hook }, |
1184564e CR |
43 | |
44 | /* make this an alias for backward compatibility */ | |
45 | { "pushnonfastforward", &advice_push_update_rejected } | |
75194438 JK |
46 | }; |
47 | ||
38ef61cf RR |
48 | void advise(const char *advice, ...) |
49 | { | |
23cb5bf3 | 50 | struct strbuf buf = STRBUF_INIT; |
38ef61cf | 51 | va_list params; |
23cb5bf3 | 52 | const char *cp, *np; |
38ef61cf RR |
53 | |
54 | va_start(params, advice); | |
447b99c8 | 55 | strbuf_vaddf(&buf, advice, params); |
38ef61cf | 56 | va_end(params); |
23cb5bf3 JH |
57 | |
58 | for (cp = buf.buf; *cp; cp = np) { | |
59 | np = strchrnul(cp, '\n'); | |
60 | fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp); | |
61 | if (*np) | |
62 | np++; | |
63 | } | |
64 | strbuf_release(&buf); | |
38ef61cf RR |
65 | } |
66 | ||
75194438 JK |
67 | int git_default_advice_config(const char *var, const char *value) |
68 | { | |
cf4fff57 | 69 | const char *k; |
75194438 JK |
70 | int i; |
71 | ||
cf4fff57 JK |
72 | if (!skip_prefix(var, "advice.", &k)) |
73 | return 0; | |
74 | ||
75194438 JK |
75 | for (i = 0; i < ARRAY_SIZE(advice_config); i++) { |
76 | if (strcmp(k, advice_config[i].name)) | |
77 | continue; | |
78 | *advice_config[i].preference = git_config_bool(var, value); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | return 0; | |
83 | } | |
d38a30df | 84 | |
38ef61cf | 85 | int error_resolve_conflict(const char *me) |
d38a30df | 86 | { |
8785c425 VA |
87 | if (!strcmp(me, "cherry-pick")) |
88 | error(_("Cherry-picking is not possible because you have unmerged files.")); | |
89 | else if (!strcmp(me, "commit")) | |
90 | error(_("Committing is not possible because you have unmerged files.")); | |
91 | else if (!strcmp(me, "merge")) | |
92 | error(_("Merging is not possible because you have unmerged files.")); | |
93 | else if (!strcmp(me, "pull")) | |
94 | error(_("Pulling is not possible because you have unmerged files.")); | |
95 | else if (!strcmp(me, "revert")) | |
96 | error(_("Reverting is not possible because you have unmerged files.")); | |
97 | else | |
98 | error(_("It is not possible to %s because you have unmerged files."), | |
99 | me); | |
100 | ||
23cb5bf3 | 101 | if (advice_resolve_conflict) |
d38a30df MM |
102 | /* |
103 | * Message used both when 'git commit' fails and when | |
104 | * other commands doing a merge do. | |
105 | */ | |
c057b242 | 106 | advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n" |
91e70e00 | 107 | "as appropriate to mark resolution and make a commit.")); |
38ef61cf RR |
108 | return -1; |
109 | } | |
110 | ||
111 | void NORETURN die_resolve_conflict(const char *me) | |
112 | { | |
113 | error_resolve_conflict(me); | |
8785c425 | 114 | die(_("Exiting because of an unresolved conflict.")); |
d38a30df | 115 | } |
2857093b | 116 | |
4a4cf9e8 PT |
117 | void NORETURN die_conclude_merge(void) |
118 | { | |
119 | error(_("You have not concluded your merge (MERGE_HEAD exists).")); | |
120 | if (advice_resolve_conflict) | |
b7447679 | 121 | advise(_("Please, commit your changes before merging.")); |
4a4cf9e8 PT |
122 | die(_("Exiting because of unfinished merge.")); |
123 | } | |
124 | ||
2857093b NTND |
125 | void detach_advice(const char *new_name) |
126 | { | |
e9f3cec4 VA |
127 | const char *fmt = |
128 | _("Note: checking out '%s'.\n\n" | |
2857093b NTND |
129 | "You are in 'detached HEAD' state. You can look around, make experimental\n" |
130 | "changes and commit them, and you can discard any commits you make in this\n" | |
131 | "state without impacting any branches by performing another checkout.\n\n" | |
132 | "If you want to create a new branch to retain commits you create, you may\n" | |
133 | "do so (now or later) by using -b with the checkout command again. Example:\n\n" | |
e9f3cec4 | 134 | " git checkout -b <new-branch-name>\n\n"); |
2857093b NTND |
135 | |
136 | fprintf(stderr, fmt, new_name); | |
137 | } |