fetch set_head: add warn-if-not-$branch option
Currently if we want to have a remote/HEAD locally that is different from the one on the remote, but we still want to get a warning if remote changes HEAD, our only option is to have an indiscriminate warning with "follow_remote_head" set to "warn". Add a new option "warn-if-not-$branch", where $branch is a branch name we do not wish to get a warning about. If the remote HEAD is $branch do not warn, otherwise, behave as "warn". E.g. let's assume, that our remote origin has HEAD set to "master", but locally we have "git remote set-head origin seen". Setting 'remote.origin.followRemoteHEAD = "warn"' will always print a warning, even though the remote has not changed HEAD from "master". Setting 'remote.origin.followRemoteHEAD = "warn-if-not-master" will squelch the warning message, unless the remote changes HEAD from "master". Note, that should the remote change HEAD to "seen" (which we have locally), there will still be no warning. Improve the advice message in report_set_head to also include silencing the warning message with "warn-if-not-$branch". Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ad739f525e
commit
9e2b7005be
@ -1584,10 +1584,12 @@ static void set_head_advice_msg(const char *remote, const char *head_name)
|
||||
const char message_advice_set_head[] =
|
||||
N_("Run 'git remote set-head %s %s' to follow the change, or set\n"
|
||||
"'remote.%s.followRemoteHEAD' configuration option to a different value\n"
|
||||
"if you do not want to see this message.");
|
||||
"if you do not want to see this message. Specifically running\n"
|
||||
"'git config set remote.%s.followRemoteHEAD %s' will disable the warning\n"
|
||||
"until the remote changes HEAD to something else.");
|
||||
|
||||
advise_if_enabled(ADVICE_FETCH_SET_HEAD_WARN, _(message_advice_set_head),
|
||||
remote, head_name, remote);
|
||||
remote, head_name, remote, remote, head_name);
|
||||
}
|
||||
|
||||
static void report_set_head(const char *remote, const char *head_name,
|
||||
@ -1612,7 +1614,8 @@ static void report_set_head(const char *remote, const char *head_name,
|
||||
strbuf_release(&buf_prefix);
|
||||
}
|
||||
|
||||
static int set_head(const struct ref *remote_refs, int follow_remote_head)
|
||||
static int set_head(const struct ref *remote_refs, int follow_remote_head,
|
||||
const char *no_warn_branch)
|
||||
{
|
||||
int result = 0, create_only, is_bare, was_detached;
|
||||
struct strbuf b_head = STRBUF_INIT, b_remote_head = STRBUF_INIT,
|
||||
@ -1669,7 +1672,9 @@ static int set_head(const struct ref *remote_refs, int follow_remote_head)
|
||||
result = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (follow_remote_head == FOLLOW_REMOTE_WARN && verbosity >= 0)
|
||||
if (verbosity >= 0 &&
|
||||
follow_remote_head == FOLLOW_REMOTE_WARN &&
|
||||
(!no_warn_branch || strcmp(no_warn_branch, head_name)))
|
||||
report_set_head(remote, head_name, &b_local_head, was_detached);
|
||||
|
||||
cleanup:
|
||||
@ -1898,7 +1903,8 @@ static int do_fetch(struct transport *transport,
|
||||
"you need to specify exactly one branch with the --set-upstream option"));
|
||||
}
|
||||
}
|
||||
if (set_head(remote_refs, transport->remote->follow_remote_head))
|
||||
if (set_head(remote_refs, transport->remote->follow_remote_head,
|
||||
transport->remote->no_warn_branch))
|
||||
;
|
||||
/*
|
||||
* Way too many cases where this can go wrong
|
||||
|
Reference in New Issue
Block a user