Skip to content

Commit 5ce2b97

Browse files
committed
Merge branch 'nd/clone-detached'
* nd/clone-detached: clone: fix up delay cloning conditions push: do not let configured foreign-vcs permanently clobbered clone: print advice on checking out detached HEAD clone: allow --branch to take a tag clone: refuse to clone if --branch points to bogus ref clone: --branch=<branch> always means refs/heads/<branch> clone: delay cloning until after remote HEAD checking clone: factor out remote ref writing clone: factor out HEAD update code clone: factor out checkout code clone: write detached HEAD in bare repositories t5601: add missing && cascade
2 parents 5e92376 + 9049816 commit 5ce2b97

File tree

8 files changed

+254
-159
lines changed

8 files changed

+254
-159
lines changed

Documentation/git-clone.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ objects from the source repository into a pack in the cloned repository.
147147
-b <name>::
148148
Instead of pointing the newly created HEAD to the branch pointed
149149
to by the cloned repository's HEAD, point to `<name>` branch
150-
instead. In a non-bare repository, this is the branch that will
151-
be checked out.
150+
instead. `--branch` can also take tags and treat them like
151+
detached HEAD. In a non-bare repository, this is the branch
152+
that will be checked out.
152153

153154
--upload-pack <upload-pack>::
154155
-u <upload-pack>::

advice.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@ void NORETURN die_resolve_conflict(const char *me)
7373
error_resolve_conflict(me);
7474
die("Exiting because of an unresolved conflict.");
7575
}
76+
77+
void detach_advice(const char *new_name)
78+
{
79+
const 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+
88+
fprintf(stderr, fmt, new_name);
89+
}

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ int git_default_advice_config(const char *var, const char *value);
1414
void advise(const char *advice, ...);
1515
int error_resolve_conflict(const char *me);
1616
extern void NORETURN die_resolve_conflict(const char *me);
17+
void detach_advice(const char *new_name);
1718

1819
#endif /* ADVICE_H */

builtin/checkout.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -514,20 +514,6 @@ static void report_tracking(struct branch_info *new)
514514
strbuf_release(&sb);
515515
}
516516

517-
static void detach_advice(const char *old_path, const char *new_name)
518-
{
519-
const char fmt[] =
520-
"Note: checking out '%s'.\n\n"
521-
"You are in 'detached HEAD' state. You can look around, make experimental\n"
522-
"changes and commit them, and you can discard any commits you make in this\n"
523-
"state without impacting any branches by performing another checkout.\n\n"
524-
"If you want to create a new branch to retain commits you create, you may\n"
525-
"do so (now or later) by using -b with the checkout command again. Example:\n\n"
526-
" git checkout -b new_branch_name\n\n";
527-
528-
fprintf(stderr, fmt, new_name);
529-
}
530-
531517
static void update_refs_for_switch(struct checkout_opts *opts,
532518
struct branch_info *old,
533519
struct branch_info *new)
@@ -575,7 +561,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
575561
REF_NODEREF, DIE_ON_ERR);
576562
if (!opts->quiet) {
577563
if (old->path && advice_detached_head)
578-
detach_advice(old->path, new->name);
564+
detach_advice(new->name);
579565
describe_detached_head(_("HEAD is now at"), new->commit);
580566
}
581567
} else if (new->path) { /* Switch branches. */

0 commit comments

Comments
 (0)