Skip to content

Commit fe308f5

Browse files
committed
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>
1 parent 629de47 commit fe308f5

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

builtin-prune.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,19 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
140140
init_revisions(&revs, prefix);
141141

142142
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+
}
145156
mark_reachable_objects(&revs, 1);
146157
prune_object_dir(get_object_directory());
147158

t/t5304-prune.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ test_expect_success 'prune: prune unreachable heads' '
100100
101101
'
102102

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' '
104104
105105
: > file2 &&
106106
git add file2 &&

0 commit comments

Comments
 (0)