Skip to content

Commit 284a49a

Browse files
authored
Merge pull request #433 from mstandley-tempus/handle-non-initial-commits-without-parents
handle non-initial orphan commits as current resource version
2 parents c0d34f1 + 52ed10c commit 284a49a

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

assets/check

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,18 @@ else
103103
fi
104104

105105
if [ -n "$ref" ] && git cat-file -e "$ref"; then
106-
init_commit=$(git rev-list --max-parents=0 HEAD | tail -n 1)
107-
if [ "${ref}" = "${init_commit}" ]; then
108-
reverse=true
109-
log_range="HEAD"
110-
else
111-
reverse=true
112-
log_range="${ref}~1..HEAD"
113-
fi
106+
reverse=true
107+
log_range="${ref}~1..HEAD"
108+
109+
# if ${ref} does not have parents, ${ref}~1 raises the error: "unknown revision or path not in the working tree"
110+
# the initial commit in a branch will never have parents, but rarely, subsequent commits can also be parentless
111+
orphan_commits=$(git rev-list --max-parents=0 HEAD)
112+
for orphan_commit in ${orphan_commits}; do
113+
if [ "${ref}" = "${orphan_commit}" ]; then
114+
log_range="HEAD"
115+
break
116+
fi
117+
done
114118
else
115119
log_range=""
116120
ref=""

test/check.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,28 @@ it_can_check_a_repo_having_multiple_root_commits() {
956956
"
957957
}
958958

959+
it_can_check_a_repo_having_multiple_root_commits_from_the_orphan_commit() {
960+
local repo=$(init_repo)
961+
local ref1=$(get_initial_ref $repo)
962+
local ref2=$(make_commit $repo)
963+
964+
# Same as above, but where the current version is the orphan commit.
965+
git -C $repo checkout --orphan temp $ref2
966+
git -C $repo commit -m "second root" --allow-empty
967+
git -C $repo checkout master
968+
git -C $repo merge temp --allow-unrelated-histories -m "merge commit"
969+
second_root=$(git -C $repo rev-parse HEAD^2)
970+
ref3=$(git -C $repo rev-parse HEAD)
971+
972+
check_uri_from $repo $second_root | jq -e "
973+
. == [
974+
{ref: $(echo $ref1 | jq -R .)},
975+
{ref: $(echo $ref2 | jq -R .)},
976+
{ref: $(echo $ref3 | jq -R .)}
977+
]
978+
"
979+
}
980+
959981
it_checks_with_version_depth() {
960982
local repo=$(init_repo)
961983
local ref1=$(make_commit_to_future $repo)
@@ -1040,5 +1062,6 @@ run it_can_check_with_tag_filter_given_branch_first_ref
10401062
run it_can_check_with_tag_regex_given_branch_first_ref
10411063
run it_checks_lastest_commit
10421064
run it_can_check_a_repo_having_multiple_root_commits
1065+
run it_can_check_a_repo_having_multiple_root_commits_from_the_orphan_commit
10431066
run it_checks_with_version_depth
10441067
run it_checks_uri_with_tag_filter_and_version_depth

test/helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ init_repo() {
3939
commit -q --allow-empty -m "init"
4040

4141
# create some bogus branch
42-
git checkout -b bogus
42+
git checkout -q -b bogus
4343

4444
git \
4545
-c user.name='test' \
4646
-c user.email='test@example.com' \
4747
commit -q --allow-empty -m "commit on other branch"
4848

4949
# back to master
50-
git checkout master
50+
git checkout -q master
5151

5252
# print resulting repo
5353
pwd

0 commit comments

Comments
 (0)