rpm-software-management/tito

tito fails to build on CentOS 7 with ERROR: Error running command: git rev-list --max-count=1

Napsty opened this issue · 4 comments

Napsty commented

I'm seeing a weird problem using a GitLab pipeline where tito is used to build a package for different distribution versions (CentOS 7, Rocky Linux 8, Rocky Linux 9).

The tito build command is the same on all distributions: tito build --srpm -o /tmp/tito/ --offline --debug.

Inside the CentOS 7 container I get the following error:

$ tito build --srpm -o /tmp/tito/ --offline --debug
ERROR: Error running command: git rev-list --max-count=1 
Status code: 33024
Command output: usage: git rev-list [OPTION] <commit-id>... [ -- paths... ]
  limiting output:
    --max-count=<n>
    --max-age=<epoch>
    --min-age=<epoch>
    --sparse
    --no-merges
    --min-parents=<n>
    --no-min-parents
    --max-parents=<n>
    --no-max-parents
    --remove-empty
    --all
    --branches
    --tags
    --remotes
    --stdin
    --quiet
  ordering output:
    --topo-order
    --date-order
    --reverse
  formatting output:
    --parents
    --children
    --objects | --objects-edge
    --unpacked
    --header | --pretty
    --abbrev=<n> | --no-abbrev
    --abbrev-commit
    --left-right
  special purpose:
    --bisect
    --bisect-vars
    --bisect-all
Traceback (most recent call last):
  File "/usr/bin/tito", line 9, in <module>
Creating output directory: /tmp/tito
---- Builder class is None
Importing tito.builder.Builder
Using builder class: <class 'tito.builder.main.Builder'>
Building in temp dir: /tmp/tito/rpmbuild-mypackageGXZX8G
Getting latest package info from: /builds/mem-icinga2/mypackage/.tito/packages/mypackage
Command: awk '{ print $1 ; exit }' /builds/mem-icinga2/mypackage/.tito/packages/mypackage
Status code: 0
Command output: 1.1.18-1
Command: git ls-remote ./. --tag mypackage-1.1.18-1 | awk '{ print $1 ; exit }'
Status code: 0
Command output: fatal: attempt to fetch/clone from a shallow repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
    load_entry_point('tito==0.6.24', 'console_scripts', 'tito')()
  File "/usr/lib/python2.7/site-packages/tito/cli.py", line 910, in main
    CLI().main(sys.argv[1:])
  File "/usr/lib/python2.7/site-packages/tito/cli.py", line 209, in main
    return module.main(argv)
  File "/usr/lib/python2.7/site-packages/tito/cli.py", line 391, in main
    builder_class=self.options.builder, **kwargs)
  File "/usr/lib/python2.7/site-packages/tito/common.py", line 180, in create_builder
    **kwargs)
  File "/usr/lib/python2.7/site-packages/tito/builder/main.py", line 415, in __init__
    test=self.test)
  File "/usr/lib/python2.7/site-packages/tito/common.py", line 793, in get_build_commit
    commit_id = run_command('git rev-list --max-count=1 %s' % tag_sha1)
  File "/usr/lib/python2.7/site-packages/tito/common.py", line 305, in run_command
    raise RunCommandException(command, status, output)
tito.exception.RunCommandException: Error running command: git rev-list --max-count=1 

Inside the Rocky Linux 8 and Rocky Linux 9 containers the same command runs through and works. Same code base, same git repo. Example from Rocky Linux 8 debug output:

$ tito build --srpm -o /tmp/tito/ --offline --debug
Creating output directory: /tmp/tito
---- Builder class is None
Importing tito.builder.Builder
Using builder class: <class 'tito.builder.main.Builder'>
Building in temp dir: /tmp/tito/rpmbuild-mypackageunkzemv6
Getting latest package info from: /builds/mem-icinga2/mypackage/.tito/packages/mypackage
Command: awk '{ print $1 ; exit }' /builds/mem-icinga2/mypackage/.tito/packages/mypackage
Status code: 0
Command output: 1.1.18-1
Command: git ls-remote ./. --tag mypackage-1.1.18-1 | awk '{ print $1 ; exit }'
Status code: 0
Command output: 1fdf52472f92d83b9b64c5041aa3da6a66b28167
Command: git rev-list --max-count=1 1fdf52472f92d83b9b64c5041aa3da6a66b28167
Status code: 0
Command output: b336216fb1264666072bc36f24f3f22f92e18d57
Got package metadata: ['1.1.18-1', './']
Building package [mypackage-1.1.18-1]
Creating mypackage-1.1.18.tar.gz from git tag: b336216fb1264666072bc36f24f3f22f92e18d57...
Command: git rev-list --timestamp --max-count=1 b336216fb1264666072bc36f24f3f22f92e18d57 | awk '{print $1}'
Status code: 0
Command output: 1691673456
Command: git archive --format=tar --prefix=mypackage-1.1.18/ b336216fb1264666072bc36f24f3f22f92e18d57: --output=/tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18.tar.initial
Status code: 0
Command output: 
git-archive fails if relative dir is not in git tree
Command: git archive --format=tar --prefix=mypackage-1.1.18/ b336216fb1264666072bc36f24f3f22f92e18d57: --output=/tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18.tar.initial > /dev/null
Status code: 0
Command output: 
Command: gzip -n -c < /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18.tar.tar > /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18.tar.gz
Status code: 0
Command output: 
Copying git source to: /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18
Command: cd /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/ && tar xzf mypackage-1.1.18.tar.gz
Status code: 0
Command output: 
Show contents of the directory structure we just extracted:
['.gitignore', '.tito', 'README.md', 'i2-agent-setup.sh', 'mypackage.spec', 'mypackage', 'sudoers.d']
Looking for .spec in /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18
Using file: mypackage.spec
Command: cp /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18.tar.gz /tmp/tito/
Status code: 0
Command output: 
Wrote: /tmp/tito/mypackage-1.1.18.tar.gz
Creating srpm from spec file: /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18/mypackage.spec
*NOT* using dist at all
Command: rpm --eval '%scl'
Status code: 0
Command output: %scl
Wrote: /tmp/tito/mypackage-1.1.18-1.el8.src.rpm
Command: rpmbuild  --eval '%undefine scl' --define "_topdir /tmp/tito/rpmbuild-mypackageunkzemv6" --define "_sourcedir /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES" --define "_builddir /tmp/tito/rpmbuild-mypackageunkzemv6/BUILD" --define "_srcrpmdir /tmp/tito" --define "_rpmdir /tmp/tito"   --nodeps -bs /tmp/tito/rpmbuild-mypackageunkzemv6/SOURCES/mypackage-1.1.18/mypackage.spec
Status code: 0
Found wrote line: /tmp/tito/mypackage-1.1.18-1.el8.src.rpm
Cleaning up /tmp/tito/rpmbuild-mypackageunkzemv6

Any idea what is causing this?

Using tito build --srpm -o /tmp/tito/ --offline --test works by the way, on all three distributions! But here the git commit is placed as package version which I want to avoid.

Hello @Napsty,
thank you for the report.

I am trying to reproduce the issue in docker run -it centos:7 bash on some of my repositories but Tito works fine there.

Can you please link your project repository if it is public? Alternatively, can you please try to build some other project that uses tito, so we can rule out that it is caused by your EPEL7 container?

Here are some:

  • git clone https://github.com/rpm-software-management/tito.git
  • git clone https://github.com/FrostyX/tracer.git
Napsty commented

Hey @FrostyX . Thx for taking your time here. Unfortunately the repo in question is private so I can't share it.
In a CentOS VM (not container) this strangely works. But I have a feeling that it has something to do with the git branch I'm testing the pipeline. See:

Command: git ls-remote ./. --tag mypackage-1.1.18-1 | awk '{ print $1 ; exit }'
Status code: 0
Command output: fatal: attempt to fetch/clone from a shallow repository
fatal: Could not read from remote repository.

Will try to reproduce with the two repos and update here later.

Napsty commented

Meanwhile I did some additional tests. It seems that the problem is somehow coming from the GitLab pipeline.

When using tito build --srpm --offline inside the build directory ($PWD), I'm getting the error mentioned above.
But if I clone the repo once again into a different path and run tito build --srpm --offline inside this separate path, the build works:

$ echo "${CI_COMMIT_REF_NAME}"
pipeline
$ cd /opt && git clone --branch ${CI_COMMIT_REF_NAME} https://$REPOSITORY_USERNAME:$REPOSITORY_PASSWORD@git.example.com/mem-icinga2/mypackage.git
Cloning into 'mypackage'...
$ cd /opt/mypackage
$ export pkg_version=$(awk '{ print $1 ; exit }' .tito/packages/mypackage)
$ tito build --srpm -o /tmp/tito/ --offline
Creating output directory: /tmp/tito
Building package [mypackage-1.1.18-1]
Wrote: /tmp/tito/mypackage-1.1.18.tar.gz
Wrote: /tmp/tito/mypackage-1.1.18-1.el7.src.rpm
$ ls -la /tmp/tito/
total 48
drwxr-xr-x. 2 root root    95 Nov  2 09:14 .
drwxrwxrwt. 1 root root    18 Nov  2 09:14 ..
-rw-r--r--. 1 root root 29252 Nov  2 09:14 mypackage-1.1.18-1.el7.src.rpm
-rw-r--r--. 1 root root 14840 Nov  2 09:14 mypackage-1.1.18.tar.gz

So not exactly sure why this causes troubles on CentOS 7 - but I will from now on use a git clone instead of using the local $PWD directory.

I am glad you figured out a solution that works for you and explained what is going on. Hopefully, it will help others with similar issues.

So not exactly sure why this causes troubles on CentOS 7

I don't understand it either :-/