Skip to content

Commit b09a883

Browse files
committed
Merge branch 'kh/branch-ref-syntax-advice'
When git refuses to create a branch because the proposed branch name is not a valid refname, an advice message is given to refer the user to exact naming rules. * kh/branch-ref-syntax-advice: branch: advise about ref syntax rules advice: use double quotes for regular quoting advice: use backticks for verbatim advice: make all entries stylistically consistent t3200: improve test style
2 parents 4f9b731 + 8fbd903 commit b09a883

File tree

6 files changed

+128
-108
lines changed

6 files changed

+128
-108
lines changed

Documentation/config/advice.txt

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ advice.*::
22
These variables control various optional help messages designed to
33
aid new users. When left unconfigured, Git will give the message
44
alongside instructions on how to squelch it. You can tell Git
5-
that you do not need the help message by setting these to 'false':
5+
that you do not need the help message by setting these to `false`:
66
+
77
--
88
addEmbeddedRepo::
9-
Advice on what to do when you've accidentally added one
9+
Shown when the user accidentally adds one
1010
git repo inside of another.
1111
addEmptyPathspec::
12-
Advice shown if a user runs the add command without providing
12+
Shown when the user runs `git add` without providing
1313
the pathspec parameter.
1414
addIgnoredFile::
15-
Advice shown if a user attempts to add an ignored file to
15+
Shown when the user attempts to add an ignored file to
1616
the index.
1717
amWorkDir::
18-
Advice that shows the location of the patch file when
19-
linkgit:git-am[1] fails to apply it.
18+
Shown when linkgit:git-am[1] fails to apply a patch
19+
file, to tell the user the location of the file.
2020
ambiguousFetchRefspec::
21-
Advice shown when a fetch refspec for multiple remotes maps to
21+
Shown when a fetch refspec for multiple remotes maps to
2222
the same remote-tracking branch namespace and causes branch
2323
tracking set-up to fail.
2424
checkoutAmbiguousRemoteBranchName::
25-
Advice shown when the argument to
25+
Shown when the argument to
2626
linkgit:git-checkout[1] and linkgit:git-switch[1]
2727
ambiguously resolves to a
2828
remote tracking branch on more than one remote in
@@ -33,31 +33,31 @@ advice.*::
3333
to be used by default in some situations where this
3434
advice would be printed.
3535
commitBeforeMerge::
36-
Advice shown when linkgit:git-merge[1] refuses to
36+
Shown when linkgit:git-merge[1] refuses to
3737
merge to avoid overwriting local changes.
3838
detachedHead::
39-
Advice shown when you used
39+
Shown when the user uses
4040
linkgit:git-switch[1] or linkgit:git-checkout[1]
41-
to move to the detached HEAD state, to instruct how to
42-
create a local branch after the fact.
41+
to move to the detached HEAD state, to tell the user how
42+
to create a local branch after the fact.
4343
diverging::
44-
Advice shown when a fast-forward is not possible.
44+
Shown when a fast-forward is not possible.
4545
fetchShowForcedUpdates::
46-
Advice shown when linkgit:git-fetch[1] takes a long time
46+
Shown when linkgit:git-fetch[1] takes a long time
4747
to calculate forced updates after ref updates, or to warn
4848
that the check is disabled.
4949
forceDeleteBranch::
50-
Advice shown when a user tries to delete a not fully merged
50+
Shown when the user tries to delete a not fully merged
5151
branch without the force option set.
5252
ignoredHook::
53-
Advice shown if a hook is ignored because the hook is not
53+
Shown when a hook is ignored because the hook is not
5454
set as executable.
5555
implicitIdentity::
56-
Advice on how to set your identity configuration when
57-
your information is guessed from the system username and
58-
domain name.
56+
Shown when the user's information is guessed from the
57+
system username and domain name, to tell the user how to
58+
set their identity configuration.
5959
nestedTag::
60-
Advice shown if a user attempts to recursively tag a tag object.
60+
Shown when a user attempts to recursively tag a tag object.
6161
pushAlreadyExists::
6262
Shown when linkgit:git-push[1] rejects an update that
6363
does not qualify for fast-forwarding (e.g., a tag.)
@@ -71,12 +71,12 @@ advice.*::
7171
object that is not a commit-ish, or make the remote
7272
ref point at an object that is not a commit-ish.
7373
pushNonFFCurrent::
74-
Advice shown when linkgit:git-push[1] fails due to a
74+
Shown when linkgit:git-push[1] fails due to a
7575
non-fast-forward update to the current branch.
7676
pushNonFFMatching::
77-
Advice shown when you ran linkgit:git-push[1] and pushed
78-
'matching refs' explicitly (i.e. you used ':', or
79-
specified a refspec that isn't your current branch) and
77+
Shown when the user ran linkgit:git-push[1] and pushed
78+
"matching refs" explicitly (i.e. used `:`, or
79+
specified a refspec that isn't the current branch) and
8080
it resulted in a non-fast-forward error.
8181
pushRefNeedsUpdate::
8282
Shown when linkgit:git-push[1] rejects a forced update of
@@ -87,25 +87,28 @@ advice.*::
8787
guess based on the source and destination refs what
8888
remote ref namespace the source belongs in, but where
8989
we can still suggest that the user push to either
90-
refs/heads/* or refs/tags/* based on the type of the
90+
`refs/heads/*` or `refs/tags/*` based on the type of the
9191
source object.
9292
pushUpdateRejected::
93-
Set this variable to 'false' if you want to disable
94-
'pushNonFFCurrent', 'pushNonFFMatching', 'pushAlreadyExists',
95-
'pushFetchFirst', 'pushNeedsForce', and 'pushRefNeedsUpdate'
93+
Set this variable to `false` if you want to disable
94+
`pushNonFFCurrent`, `pushNonFFMatching`, `pushAlreadyExists`,
95+
`pushFetchFirst`, `pushNeedsForce`, and `pushRefNeedsUpdate`
9696
simultaneously.
97+
refSyntax::
98+
Shown when the user provides an illegal ref name, to
99+
tell the user about the ref syntax documentation.
97100
resetNoRefresh::
98-
Advice to consider using the `--no-refresh` option to
99-
linkgit:git-reset[1] when the command takes more than 2 seconds
100-
to refresh the index after reset.
101+
Shown when linkgit:git-reset[1] takes more than 2
102+
seconds to refresh the index after reset, to tell the user
103+
that they can use the `--no-refresh` option.
101104
resolveConflict::
102-
Advice shown by various commands when conflicts
105+
Shown by various commands when conflicts
103106
prevent the operation from being performed.
104107
rmHints::
105-
In case of failure in the output of linkgit:git-rm[1],
106-
show directions on how to proceed from the current state.
108+
Shown on failure in the output of linkgit:git-rm[1], to
109+
give directions on how to proceed from the current state.
107110
sequencerInUse::
108-
Advice shown when a sequencer command is already in progress.
111+
Shown when a sequencer command is already in progress.
109112
skippedCherryPicks::
110113
Shown when linkgit:git-rebase[1] skips a commit that has already
111114
been cherry-picked onto the upstream branch.
@@ -123,30 +126,30 @@ advice.*::
123126
by linkgit:git-switch[1] or
124127
linkgit:git-checkout[1] when switching branches.
125128
statusUoption::
126-
Advise to consider using the `-u` option to linkgit:git-status[1]
127-
when the command takes more than 2 seconds to enumerate untracked
128-
files.
129+
Shown when linkgit:git-status[1] takes more than 2
130+
seconds to enumerate untracked files, to tell the user that
131+
they can use the `-u` option.
129132
submoduleAlternateErrorStrategyDie::
130-
Advice shown when a submodule.alternateErrorStrategy option
133+
Shown when a submodule.alternateErrorStrategy option
131134
configured to "die" causes a fatal error.
132135
submoduleMergeConflict::
133136
Advice shown when a non-trivial submodule merge conflict is
134137
encountered.
135138
submodulesNotUpdated::
136-
Advice shown when a user runs a submodule command that fails
139+
Shown when a user runs a submodule command that fails
137140
because `git submodule update --init` was not run.
138141
suggestDetachingHead::
139-
Advice shown when linkgit:git-switch[1] refuses to detach HEAD
142+
Shown when linkgit:git-switch[1] refuses to detach HEAD
140143
without the explicit `--detach` option.
141144
updateSparsePath::
142-
Advice shown when either linkgit:git-add[1] or linkgit:git-rm[1]
145+
Shown when either linkgit:git-add[1] or linkgit:git-rm[1]
143146
is asked to update index entries outside the current sparse
144147
checkout.
145148
waitingForEditor::
146-
Print a message to the terminal whenever Git is waiting for
147-
editor input from the user.
149+
Shown when Git is waiting for editor input. Relevant
150+
when e.g. the editor is not launched inside the terminal.
148151
worktreeAddOrphan::
149-
Advice shown when a user tries to create a worktree from an
150-
invalid reference, to instruct how to create a new unborn
152+
Shown when the user tries to create a worktree from an
153+
invalid reference, to tell the user how to create a new unborn
151154
branch instead.
152155
--

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static struct {
6868
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName" },
6969
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected" },
7070
[ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward" }, /* backwards compatibility */
71+
[ADVICE_REF_SYNTAX] = { "refSyntax" },
7172
[ADVICE_RESET_NO_REFRESH_WARNING] = { "resetNoRefresh" },
7273
[ADVICE_RESOLVE_CONFLICT] = { "resolveConflict" },
7374
[ADVICE_RM_HINTS] = { "rmHints" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum advice_type {
3636
ADVICE_PUSH_UNQUALIFIED_REF_NAME,
3737
ADVICE_PUSH_UPDATE_REJECTED,
3838
ADVICE_PUSH_UPDATE_REJECTED_ALIAS,
39+
ADVICE_REF_SYNTAX,
3940
ADVICE_RESET_NO_REFRESH_WARNING,
4041
ADVICE_RESOLVE_CONFLICT,
4142
ADVICE_RM_HINTS,

branch.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,12 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
370370
*/
371371
int validate_branchname(const char *name, struct strbuf *ref)
372372
{
373-
if (strbuf_check_branch_ref(ref, name))
374-
die(_("'%s' is not a valid branch name"), name);
373+
if (strbuf_check_branch_ref(ref, name)) {
374+
int code = die_message(_("'%s' is not a valid branch name"), name);
375+
advise_if_enabled(ADVICE_REF_SYNTAX,
376+
_("See `man git check-ref-format`"));
377+
exit(code);
378+
}
375379

376380
return ref_exists(ref->buf);
377381
}

builtin/branch.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,12 @@ static void copy_or_rename_branch(const char *oldname, const char *newname, int
582582
*/
583583
if (ref_exists(oldref.buf))
584584
recovery = 1;
585-
else
586-
die(_("invalid branch name: '%s'"), oldname);
585+
else {
586+
int code = die_message(_("invalid branch name: '%s'"), oldname);
587+
advise_if_enabled(ADVICE_REF_SYNTAX,
588+
_("See `man git check-ref-format`"));
589+
exit(code);
590+
}
587591
}
588592

589593
for (int i = 0; worktrees[i]; i++) {

0 commit comments

Comments
 (0)