Skip to content

Commit

Permalink
Merge branch 'nd/clone-detached'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gitster committed Feb 1, 2012
2 parents 5e92376 + 9049816 commit 5ce2b97
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 159 deletions.
5 changes: 3 additions & 2 deletions Documentation/git-clone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ objects from the source repository into a pack in the cloned repository.
-b <name>::
Instead of pointing the newly created HEAD to the branch pointed
to by the cloned repository's HEAD, point to `<name>` branch
instead. In a non-bare repository, this is the branch that will
be checked out.
instead. `--branch` can also take tags and treat them like
detached HEAD. In a non-bare repository, this is the branch
that will be checked out.

--upload-pack <upload-pack>::
-u <upload-pack>::
Expand Down
14 changes: 14 additions & 0 deletions advice.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ void NORETURN die_resolve_conflict(const char *me)
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);
}
1 change: 1 addition & 0 deletions advice.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ int git_default_advice_config(const char *var, const char *value);
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 */
16 changes: 1 addition & 15 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,20 +514,6 @@ static void report_tracking(struct branch_info *new)
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)
Expand Down Expand Up @@ -575,7 +561,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
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. */
Expand Down
Loading

0 comments on commit 5ce2b97

Please sign in to comment.