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