Skip to content

Commit ded44af

Browse files
committed
Merge branch 'bc/filter-process'
Code simplification and test coverage enhancement. * bc/filter-process: t2060: add a test for switch with --orphan and --discard-changes builtin/checkout: simplify metadata initialization
2 parents a8ecd01 + 8d3e33d commit ded44af

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

builtin/checkout.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
621621
opts.src_index = &the_index;
622622
opts.dst_index = &the_index;
623623
init_checkout_metadata(&opts.meta, info->refname,
624-
info->commit ? &info->commit->object.oid :
625-
is_null_oid(&info->oid) ? &tree->object.oid :
626-
&info->oid,
624+
info->commit ? &info->commit->object.oid : &null_oid,
627625
NULL);
628626
parse_tree(tree);
629627
init_tree_desc(&tree_desc, tree->buffer, tree->size);

t/t2060-switch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ test_expect_success 'new orphan branch from empty' '
6868
test_cmp expected tracked-files
6969
'
7070

71+
test_expect_success 'orphan branch works with --discard-changes' '
72+
test_when_finished git switch master &&
73+
echo foo >foo.txt &&
74+
git switch --discard-changes --orphan new-orphan2 &&
75+
git ls-files >tracked-files &&
76+
test_must_be_empty tracked-files
77+
'
78+
7179
test_expect_success 'switching ignores file of same branch name' '
7280
test_when_finished git switch master &&
7381
: >first-branch &&

0 commit comments

Comments
 (0)