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