Skip to content

Commit 86af2ca

Browse files
chriscoolgitster
authored andcommitted
builtin-replace: use "usage_msg_opt" to give better error messages
Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 451bb21 commit 86af2ca

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

builtin-replace.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,30 +124,36 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
124124
argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
125125

126126
if (list && delete)
127-
usage_with_options(git_replace_usage, options);
127+
usage_msg_opt("-l and -d cannot be used together",
128+
git_replace_usage, options);
128129

129130
if (force && (list || delete))
130-
usage_with_options(git_replace_usage, options);
131+
usage_msg_opt("-f cannot be used with -d or -l",
132+
git_replace_usage, options);
131133

132134
/* Delete refs */
133135
if (delete) {
134136
if (argc < 1)
135-
usage_with_options(git_replace_usage, options);
137+
usage_msg_opt("-d needs at least one argument",
138+
git_replace_usage, options);
136139
return for_each_replace_name(argv, delete_replace_ref);
137140
}
138141

139142
/* Replace object */
140143
if (!list && argc) {
141144
if (argc != 2)
142-
usage_with_options(git_replace_usage, options);
145+
usage_msg_opt("bad number of arguments",
146+
git_replace_usage, options);
143147
return replace_object(argv[0], argv[1], force);
144148
}
145149

146150
/* List refs, even if "list" is not set */
147151
if (argc > 1)
148-
usage_with_options(git_replace_usage, options);
152+
usage_msg_opt("only one pattern can be given with -l",
153+
git_replace_usage, options);
149154
if (force)
150-
usage_with_options(git_replace_usage, options);
155+
usage_msg_opt("-f needs some arguments",
156+
git_replace_usage, options);
151157

152158
return list_replace_refs(argv[0]);
153159
}

0 commit comments

Comments
 (0)