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