mirror of
https://github.com/git/git.git
synced 2024-05-12 00:06:36 +02:00
clone: print advice on checking out detached HEAD
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5a7d5b683f
commit
2857093ba1
14
advice.c
14
advice.c
|
@ -64,3 +64,17 @@ void NORETURN die_resolve_conflict(const char *me)
|
||||||
error_resolve_conflict(me);
|
error_resolve_conflict(me);
|
||||||
die("Exiting because of an unresolved conflict.");
|
die("Exiting because of an unresolved conflict.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void detach_advice(const char *new_name)
|
||||||
|
{
|
||||||
|
const char fmt[] =
|
||||||
|
"Note: checking out '%s'.\n\n"
|
||||||
|
"You are in 'detached HEAD' state. You can look around, make experimental\n"
|
||||||
|
"changes and commit them, and you can discard any commits you make in this\n"
|
||||||
|
"state without impacting any branches by performing another checkout.\n\n"
|
||||||
|
"If you want to create a new branch to retain commits you create, you may\n"
|
||||||
|
"do so (now or later) by using -b with the checkout command again. Example:\n\n"
|
||||||
|
" git checkout -b new_branch_name\n\n";
|
||||||
|
|
||||||
|
fprintf(stderr, fmt, new_name);
|
||||||
|
}
|
||||||
|
|
1
advice.h
1
advice.h
|
@ -14,5 +14,6 @@ int git_default_advice_config(const char *var, const char *value);
|
||||||
void advise(const char *advice, ...);
|
void advise(const char *advice, ...);
|
||||||
int error_resolve_conflict(const char *me);
|
int error_resolve_conflict(const char *me);
|
||||||
extern void NORETURN die_resolve_conflict(const char *me);
|
extern void NORETURN die_resolve_conflict(const char *me);
|
||||||
|
void detach_advice(const char *new_name);
|
||||||
|
|
||||||
#endif /* ADVICE_H */
|
#endif /* ADVICE_H */
|
||||||
|
|
|
@ -514,20 +514,6 @@ static void report_tracking(struct branch_info *new)
|
||||||
strbuf_release(&sb);
|
strbuf_release(&sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void detach_advice(const char *old_path, const char *new_name)
|
|
||||||
{
|
|
||||||
const char fmt[] =
|
|
||||||
"Note: checking out '%s'.\n\n"
|
|
||||||
"You are in 'detached HEAD' state. You can look around, make experimental\n"
|
|
||||||
"changes and commit them, and you can discard any commits you make in this\n"
|
|
||||||
"state without impacting any branches by performing another checkout.\n\n"
|
|
||||||
"If you want to create a new branch to retain commits you create, you may\n"
|
|
||||||
"do so (now or later) by using -b with the checkout command again. Example:\n\n"
|
|
||||||
" git checkout -b new_branch_name\n\n";
|
|
||||||
|
|
||||||
fprintf(stderr, fmt, new_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_refs_for_switch(struct checkout_opts *opts,
|
static void update_refs_for_switch(struct checkout_opts *opts,
|
||||||
struct branch_info *old,
|
struct branch_info *old,
|
||||||
struct branch_info *new)
|
struct branch_info *new)
|
||||||
|
@ -575,7 +561,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
|
||||||
REF_NODEREF, DIE_ON_ERR);
|
REF_NODEREF, DIE_ON_ERR);
|
||||||
if (!opts->quiet) {
|
if (!opts->quiet) {
|
||||||
if (old->path && advice_detached_head)
|
if (old->path && advice_detached_head)
|
||||||
detach_advice(old->path, new->name);
|
detach_advice(new->name);
|
||||||
describe_detached_head(_("HEAD is now at"), new->commit);
|
describe_detached_head(_("HEAD is now at"), new->commit);
|
||||||
}
|
}
|
||||||
} else if (new->path) { /* Switch branches. */
|
} else if (new->path) { /* Switch branches. */
|
||||||
|
|
|
@ -563,7 +563,10 @@ static int checkout(void)
|
||||||
"unable to checkout.\n"));
|
"unable to checkout.\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (strcmp(head, "HEAD")) {
|
if (!strcmp(head, "HEAD")) {
|
||||||
|
if (advice_detached_head)
|
||||||
|
detach_advice(sha1_to_hex(sha1));
|
||||||
|
} else {
|
||||||
if (prefixcmp(head, "refs/heads/"))
|
if (prefixcmp(head, "refs/heads/"))
|
||||||
die(_("HEAD not found below refs/heads!"));
|
die(_("HEAD not found below refs/heads!"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue