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