29
#define BUILTIN_REFLOG_EXISTS_USAGE \
30
N_("git reflog exists <ref>")
31
32
+#define BUILTIN_REFLOG_DROP_USAGE \
33
+ N_("git reflog drop [--all [--single-worktree] | <refs>...]")
34
+
35
static const char *const reflog_show_usage[] = {
36
BUILTIN_REFLOG_SHOW_USAGE,
37
NULL,
57
NULL,
58
};
59
60
+static const char *const reflog_drop_usage[] = {
61
+ BUILTIN_REFLOG_DROP_USAGE,
62
+ NULL,
63
+};
64
+
65
static const char *const reflog_usage[] = {
66
BUILTIN_REFLOG_SHOW_USAGE,
67
BUILTIN_REFLOG_LIST_USAGE,
68
BUILTIN_REFLOG_EXPIRE_USAGE,
69
BUILTIN_REFLOG_DELETE_USAGE,
70
+ BUILTIN_REFLOG_DROP_USAGE,
71
BUILTIN_REFLOG_EXISTS_USAGE,
72
NULL
73
};
458
refname);
459
}
460
461
+static int cmd_reflog_drop(int argc, const char **argv, const char *prefix,
462
+ struct repository *repo)
463
+{
464
+ int ret = 0, do_all = 0, single_worktree = 0;
465
+ const struct option options[] = {
466
+ OPT_BOOL(0, "all", &do_all, N_("drop the reflogs of all references")),
467
+ OPT_BOOL(0, "single-worktree", &single_worktree,
468
+ N_("drop reflogs from the current worktree only")),
469
+ OPT_END()
470
+ };
471
+
472
+ argc = parse_options(argc, argv, prefix, options, reflog_drop_usage, 0);
473
+
474
+ if (argc && do_all)
475
+ usage(_("references specified along with --all"));
476
+
477
+ if (do_all) {
478
+ struct worktree_reflogs collected = {
479
+ .reflogs = STRING_LIST_INIT_DUP,
480
+ };
481
+ struct string_list_item *item;
482
+ struct worktree **worktrees, **p;
483
+
484
+ worktrees = get_worktrees();
485
+ for (p = worktrees; *p; p++) {
486
+ if (single_worktree && !(*p)->is_current)
487
+ continue;
488
+ collected.worktree = *p;
489
+ refs_for_each_reflog(get_worktree_ref_store(*p),
490
+ collect_reflog, &collected);
491
+ }
492
+ free_worktrees(worktrees);
493
+
494
+ for_each_string_list_item(item, &collected.reflogs)
495
+ ret |= refs_delete_reflog(get_main_ref_store(repo),
496
+ item->string);
497
+ string_list_clear(&collected.reflogs, 0);
498
+
499
+ return ret;
500
+ }
501
+
502
+ for (int i = 0; i < argc; i++) {
503
+ char *ref;
504
+ if (!repo_dwim_log(repo, argv[i], strlen(argv[i]), NULL, &ref)) {
505
+ ret |= error(_("reflog could not be found: '%s'"), argv[i]);
506
+ continue;
507
+ }
508
+
509
+ ret |= refs_delete_reflog(get_main_ref_store(repo), ref);
510
+ free(ref);
511
+ }
512
+
513
+ return ret;
514
+}
515
+
516
/*
517
* main "reflog"
518
*/
455
-
519
int cmd_reflog(int argc,
520
const char **argv,
521
const char *prefix,
528
OPT_SUBCOMMAND("expire", &fn, cmd_reflog_expire),
529
OPT_SUBCOMMAND("delete", &fn, cmd_reflog_delete),
530
OPT_SUBCOMMAND("exists", &fn, cmd_reflog_exists),
531
+ OPT_SUBCOMMAND("drop", &fn, cmd_reflog_drop),
532
OPT_END()
533
};
534