summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5a7d5b6)
raw | patch | inline | side by side (parent: 5a7d5b6)
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | |
Mon, 16 Jan 2012 09:46:16 +0000 (16:46 +0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 17 Jan 2012 00:26:27 +0000 (16:26 -0800) |
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
advice.c | patch | blob | history | |
advice.h | patch | blob | history | |
builtin/checkout.c | patch | blob | history | |
builtin/clone.c | patch | blob | history |
diff --git a/advice.c b/advice.c
index e02e632df380a8e9772d9cd9b1282204c56a7d4e..3e1a145bf0b7eb482246f965da0997ab42706199 100644 (file)
--- a/advice.c
+++ b/advice.c
error_resolve_conflict(me);
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);
+}
diff --git a/advice.h b/advice.h
index e5d0af782b1445b48b49cd58f481a593268c3384..7bda45b83e34b8417e5c20219c7424bb35b3d681 100644 (file)
--- a/advice.h
+++ b/advice.h
void advise(const char *advice, ...);
int error_resolve_conflict(const char *me);
extern void NORETURN die_resolve_conflict(const char *me);
+void detach_advice(const char *new_name);
#endif /* ADVICE_H */
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f1984d9933c526bcd2af66fd745dc64a607ac19b..5bf96ba4d41cc9c16bb5ccabe9857724ecfe2c12 100644 (file)
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
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,
struct branch_info *old,
struct branch_info *new)
REF_NODEREF, DIE_ON_ERR);
if (!opts->quiet) {
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);
}
} else if (new->path) { /* Switch branches. */
diff --git a/builtin/clone.c b/builtin/clone.c
index 651b4cc20bd932876e35dd16f6ac2a7ecfc9b501..72eebca5350c740e39c07737685204acfb9f8c80 100644 (file)
--- a/builtin/clone.c
+++ b/builtin/clone.c
"unable to checkout.\n"));
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/"))
die(_("HEAD not found below refs/heads!"));
}