Skip to content

Commit 3915f9a

Browse files
committed
Merge branch 'jc/parseopt-expiry-errors'
"git gc --prune=nonsense" spent long time repacking and then silently failed when underlying "git prune --expire=nonsense" failed to parse its command line. This has been corrected. * jc/parseopt-expiry-errors: parseopt: handle malformed --expire arguments more nicely gc: do not upcase error message shown with die()
2 parents ad3207e + 8ab5aa4 commit 3915f9a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

builtin/gc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
354354
const char *name;
355355
pid_t pid;
356356
int daemonized = 0;
357+
timestamp_t dummy;
357358

358359
struct option builtin_gc_options[] = {
359360
OPT__QUIET(&quiet, N_("suppress progress reporting")),
@@ -382,7 +383,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
382383
/* default expiry time, overwritten in gc_config */
383384
gc_config();
384385
if (parse_expiry_date(gc_log_expire, &gc_log_expire_time))
385-
die(_("Failed to parse gc.logexpiry value %s"), gc_log_expire);
386+
die(_("failed to parse gc.logexpiry value %s"), gc_log_expire);
386387

387388
if (pack_refs < 0)
388389
pack_refs = !is_bare_repository();
@@ -392,6 +393,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
392393
if (argc > 0)
393394
usage_with_options(builtin_gc_usage, builtin_gc_options);
394395

396+
if (prune_expire && parse_expiry_date(prune_expire, &dummy))
397+
die(_("failed to parse prune expiry value %s"), prune_expire);
398+
395399
if (aggressive) {
396400
argv_array_push(&repack, "-f");
397401
if (aggressive_depth > 0)

parse-options-cb.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
3838
int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
3939
int unset)
4040
{
41-
return parse_expiry_date(arg, (timestamp_t *)opt->value);
41+
if (unset)
42+
arg = "never";
43+
if (parse_expiry_date(arg, (timestamp_t *)opt->value))
44+
die(_("malformed expiration date '%s'"), arg);
45+
return 0;
4246
}
4347

4448
int parse_opt_color_flag_cb(const struct option *opt, const char *arg,

t/t5304-prune.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,4 +320,14 @@ test_expect_success 'prune: handle HEAD reflog in multiple worktrees' '
320320
test_cmp expected actual
321321
'
322322

323+
test_expect_success 'prune: handle expire option correctly' '
324+
test_must_fail git prune --expire 2>error &&
325+
test_i18ngrep "requires a value" error &&
326+
327+
test_must_fail git prune --expire=nyah 2>error &&
328+
test_i18ngrep "malformed expiration" error &&
329+
330+
git prune --no-expire
331+
'
332+
323333
test_done

0 commit comments

Comments
 (0)