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