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