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