File tree Expand file tree Collapse file tree 4 files changed +20
-16
lines changed Expand file tree Collapse file tree 4 files changed +20
-16
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,17 @@ void NORETURN die_resolve_conflict(const char *me)
64
64
error_resolve_conflict (me );
65
65
die ("Exiting because of an unresolved conflict." );
66
66
}
67
+
68
+ void detach_advice (const char * new_name )
69
+ {
70
+ const char fmt [] =
71
+ "Note: checking out '%s'.\n\n"
72
+ "You are in 'detached HEAD' state. You can look around, make experimental\n"
73
+ "changes and commit them, and you can discard any commits you make in this\n"
74
+ "state without impacting any branches by performing another checkout.\n\n"
75
+ "If you want to create a new branch to retain commits you create, you may\n"
76
+ "do so (now or later) by using -b with the checkout command again. Example:\n\n"
77
+ " git checkout -b new_branch_name\n\n" ;
78
+
79
+ fprintf (stderr , fmt , new_name );
80
+ }
Original file line number Diff line number Diff line change @@ -14,5 +14,6 @@ int git_default_advice_config(const char *var, const char *value);
14
14
void advise (const char * advice , ...);
15
15
int error_resolve_conflict (const char * me );
16
16
extern void NORETURN die_resolve_conflict (const char * me );
17
+ void detach_advice (const char * new_name );
17
18
18
19
#endif /* ADVICE_H */
Original file line number Diff line number Diff line change @@ -514,20 +514,6 @@ static void report_tracking(struct branch_info *new)
514
514
strbuf_release (& sb );
515
515
}
516
516
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
-
531
517
static void update_refs_for_switch (struct checkout_opts * opts ,
532
518
struct branch_info * old ,
533
519
struct branch_info * new )
@@ -575,7 +561,7 @@ static void update_refs_for_switch(struct checkout_opts *opts,
575
561
REF_NODEREF , DIE_ON_ERR );
576
562
if (!opts -> quiet ) {
577
563
if (old -> path && advice_detached_head )
578
- detach_advice (old -> path , new -> name );
564
+ detach_advice (new -> name );
579
565
describe_detached_head (_ ("HEAD is now at" ), new -> commit );
580
566
}
581
567
} else if (new -> path ) { /* Switch branches. */
Original file line number Diff line number Diff line change @@ -563,7 +563,10 @@ static int checkout(void)
563
563
"unable to checkout.\n" ));
564
564
return 0 ;
565
565
}
566
- if (strcmp (head , "HEAD" )) {
566
+ if (!strcmp (head , "HEAD" )) {
567
+ if (advice_detached_head )
568
+ detach_advice (sha1_to_hex (sha1 ));
569
+ } else {
567
570
if (prefixcmp (head , "refs/heads/" ))
568
571
die (_ ("HEAD not found below refs/heads!" ));
569
572
}
You can’t perform that action at this time.
0 commit comments