@matheusbsbs / matheus-bagliano / commits / fe308f5373
Fork 0

builtin-prune: protect objects listed on the command line

Finally, this resurrects the documented behaviour to protect other objects listed on the command line from getting pruned. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 24, 2008 at 23:20 UTC fe308f53730f168be65c57c46e5c573b449b3e32
2 files changed +14 -3
builtin-prune.c
+13 -2
@@ -140,8 +140,19 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
140 init_revisions(&revs, prefix);
141
142 argc = parse_options(argc, argv, options, prune_usage, 0);
143 - if (argc)
144 - die ("unrecognized argument: %s", name);
143 + while (argc--) {
144 + unsigned char sha1[20];
145 + const char *name = *argv++;
146 +
147 + if (!get_sha1(name, sha1)) {
148 + struct object *object = parse_object(sha1);
149 + if (!object)
150 + die("bad object: %s", name);
151 + add_pending_object(&revs, object, "");
152 + }
153 + else
154 + die("unrecognized argument: %s", name);
155 + }
156 mark_reachable_objects(&revs, 1);
157 prune_object_dir(get_object_directory());
158
t/t5304-prune.sh
+1 -1
@@ -100,7 +100,7 @@ test_expect_success 'prune: prune unreachable heads' '
100
101 '
102
103 -test_expect_failure 'prune: do not prune heads listed as an argument' '
103 +test_expect_success 'prune: do not prune heads listed as an argument' '
104
105 : > file2 &&
106 git add file2 &&