cherry-pick shows confusing message
I was looking at the build log of a https://github.com/wolfi-dev/os/pull/27452/ here
It ends like:
2024/09/03 14:50:50 INFO built image layer tarball as /temp/apko-temp-1821752880/apko-aarch64.tar.gz
2024/09/03 14:50:50 INFO using /temp/apko-temp-1821752880/apko-aarch64.tar.gz for image layer
2024/09/03 14:50:55 INFO ImgRef = /temp/melange-guest-3599558897
2024/09/03 14:50:55 INFO running step "Check out sources from git"
2024/09/03 14:50:55 INFO [git checkout] repo='https://github.com/openssl/openssl.git' dest='.' depth='1'\
branch='' tag='openssl-3.3.2' expcommit='fb7fab9fa6f4869eaa8fbb97e0d593159f03ffe4' recurse='false'
2024/09/03 14:50:55 INFO [git checkout] execute: git config --global --add safe.directory /tmp/tmp.vpbbqP
2024/09/03 14:50:55 INFO [git checkout] execute: git config --global --add safe.directory /home/build
2024/09/03 14:50:55 INFO [git checkout] execute: git clone --quiet --origin=origin --config=user.name=Melange Build \
[email protected] --config=advice.detachedHead=false \
--branch=openssl-3.3.2 --depth=1 https://github.com/openssl/openssl.git /tmp/tmp.vpbbqP
2024/09/03 14:50:58 INFO [git checkout] execute: cd /tmp/tmp.vpbbqP
2024/09/03 14:50:58 INFO [git checkout] tar -c . | tar -C "/home/build" -x
2024/09/03 14:50:59 INFO [git checkout] execute: cd /home/build
2024/09/03 14:50:59 INFO [git checkout] execute: git config --global --add safe.directory /home/build
2024/09/03 14:50:59 INFO [git checkout] execute: git fetch --quiet origin --depth=1 --no-tags +refs/tags/openssl-3.3.2:refs/origin/tags/openssl-3.3.2
2024/09/03 14:50:59 INFO [git checkout] execute: git checkout --quiet origin/tags/openssl-3.3.2
2024/09/03 14:50:59 INFO [git checkout] tag openssl-3.3.2 is fb7fab9fa6f4869eaa8fbb97e0d593159f03ffe4
2024/09/03 14:50:59 INFO [git checkout] Setting commit date to Jan 1, 1980 (SOURCE_DATE_EPOCH found 0)
2024/09/03 14:50:59 INFO [git checkout] execute: git fetch origin openssl-3.3:openssl-3.3
2024/09/03 14:50:59 WARN From https://github.com/openssl/openssl
2024/09/03 14:50:59 WARN * [new branch] openssl-3.3 -> openssl-3.3
2024/09/03 14:50:59 INFO [git checkout] execute: env GIT_COMMITTER_DATE=@315532800 git cherry-pick -x e86ac436f0bd54d4517745483e2315650fae7b2c
2024/09/03 14:50:59 WARN fatal: bad object e86ac436f0bd54d4517745483e2315650fae7b2c
2024/09/03 14:50:59 INFO [git checkout] failed to cherry-pick e86ac436f0bd54d4517745483e2315650fae7b2c from branch openssl-3.3
2024/09/03 14:50:59 INFO [git checkout] FAIL failed to apply cherry-pick
2024/09/03 14:50:59 ERRO ERROR: failed to build package. the build environment has been preserved:
2024/09/03 14:50:59 INFO workspace dir: /temp/melange-workspace-391569645
2024/09/03 14:50:59 INFO guest dir: /temp/melange-guest-2797409342
2024/09/03 14:50:59 ERRO failed to build package: unable to run package openssl pipeline: unable to run pipeline: unable to run pipeline: exit status 1
make[1]: *** [Makefile:111: packages/aarch64/openssl-3.3.2-r0.apk] Error 1
The message bad object e86ac... did not make sense to me. We explicitly did git fetch origin openssl-3.3:openssl-3.3. It should have fetched that commit id I wondered if maybe openssl mucked with their git history, as that commit was on the openssl-3.3 branch.
Further investigation shows that the 'fetch origin openssl-3.3:openssl-3.3' does not cross the .git/shallow boundary. that was established when we git cloned and pulled the openssl-3.3.2 tag. The subsequent fetch of the openssl-3.3 branch then doesn't actually do anything because it now points to the same commit (or maybe a couple ahead) of the 3.3.2 tag.
So,
- The fetch works when the branch mentioned is newer than the tag pulled.
- It errors with 'bad object' message if the branch pulled is the same as the tag we cloned with (or newer) because the fetch will stop at the tag.
- to ensure that we get all the commits on a branch, we need to use
--unshallowon the fetch. This will actually pull a lot more commits in almost all cases.