Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume running in git directory #174

Closed
nirizr opened this issue Dec 30, 2017 · 9 comments · Fixed by #176
Closed

Don't assume running in git directory #174

nirizr opened this issue Dec 30, 2017 · 9 comments · Fixed by #176

Comments

@nirizr
Copy link
Contributor

nirizr commented Dec 30, 2017

Right now coveralls assumes it runs inside a git directory while executing the following two lines:

   rev = run_command('git', 'rev-parse', '--abbrev-ref', 'HEAD').strip()
   remotes = run_command('git', 'remote', '-v').splitlines()

However they are not really mandatory. First, the only use of rev is as kind of a last resort default value, which is often calculated without being used (as more often than not, environment variables supersede it).

The other variable, remotes is used but does not seem to be crucial to the operation of coveralls.
I would greatly appreciate if coveralls could function outside of git directories either by not providing the remotes parameter or by manually providing it using an environment variable or command line argument.

@giorgiosironi
Copy link

I stumbled upon this today when running tests (and hence coverage and coveralls) inside a Docker container. We don't copy the whole Git repository in the container image, so these calls fail.

There is also this section:

            'head': {
                'id': gitlog('%H'),
                'author_name': gitlog('%aN'),
                'author_email': gitlog('%ae'),
                'committer_name': gitlog('%cN'),
                'committer_email': gitlog('%ce'),
                'message': gitlog('%s'),
            },

which runs git log 6 times.

@wwaltersp
Copy link

This is preventing us from having coveralls write a status to the triggering PR commit hash when building against the PR with the tip of the target branch merged in. The id value is being set to the tip of the merged branches and it doesn't look like there is a way to override that setting.

@TheKevJames
Copy link
Owner

Hey folks,

Sorry for the lack of response on this -- the git chunk used to be a mandatory field on Coveralls' side, but I see they have now changed that. I also agree that this code path can be cleaned up to avoid running git log so many times.

I would be happy to accept a PR for either or both of those changes (ie. "only attach git data when the .git folder is present" and/or "run git log once instead of six times") -- I'll try to get to this myself at some point, but I've been very busy lately and can't guarantee I'll be able to get to it any time soon.

@nirizr
Copy link
Contributor Author

nirizr commented Feb 22, 2018

I'm gonna give a try at PRing silently omitting the git request json key. Expect it in an hour or two tops.

@TheKevJames
Copy link
Owner

This issue has been fixed by @nirizr and I will post back here once I cut a new release. Keeping this issue open as a reminder to myself to de-dupe the gitlog commands.

@TheKevJames
Copy link
Owner

@nirizr @wwaltersp @giorgiosironi I have just released version 1.3.0, which includes @nirizr 's fix for this issue. Sorry this took so long!

@Themanwithoutaplan
Copy link
Contributor

I've just hit this when working with a Mercurial repo. Should be running the most recent version of coveralls which should be able to work without git. Obviously not.

cov runtests: commands[1] | coveralls
Submitting coverage to coveralls.io...
Traceback (most recent call last):
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/bin/coveralls", line 11, in <module>
    sys.exit(main())
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/lib/python3.6/site-packages/coveralls/cli.py", line 76, in main
    result = coverallz.wear()
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/lib/python3.6/site-packages/coveralls/api.py", line 160, in wear
    json_string = self.create_report()
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/lib/python3.6/site-packages/coveralls/api.py", line 178, in create_report
    data = self.create_data()
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/lib/python3.6/site-packages/coveralls/api.py", line 231, in create_data
    self._data.update(git_info())
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/lib/python3.6/site-packages/coveralls/git.py", line 66, in git_info
    run_command('git', 'rev-parse', '--abbrev-ref', 'HEAD'))
  File "/opt/atlassian/pipelines/agent/build/.tox/cov/lib/python3.6/site-packages/coveralls/git.py", line 13, in run_command
    stderr=subprocess.PIPE)
  File "/usr/lib64/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/usr/lib64/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'git': 'git'
ERROR: InvocationError for command '/opt/atlassian/pipelines/agent/build/.tox/cov/bin/coveralls' (exited with code 1)

nirizr added a commit to nirizr/coveralls-python that referenced this issue Sep 12, 2018
Addresses this comment: TheKevJames#174 (comment)

Previously, git info was omitted if git was installed but the .git directory was missing.
This fix will also omit git info in case git itself is missing (unless, of course, the environment args are there).
@nirizr
Copy link
Contributor Author

nirizr commented Sep 17, 2018

@Themanwithoutaplan PR linked above should solve this issue, which is caused by the git command being unavailable (which wasn't handled previously).

@Themanwithoutaplan
Copy link
Contributor

I'm running a version that should contain the merged PR – it contains my own for using Mercurial instead of Git. Will try and doublecheck in docker and see if I can remove the dependency.

nirizr added a commit to nirizr/coveralls-python that referenced this issue Sep 28, 2018
Addresses this comment: TheKevJames#174 (comment)

Previously, git info was omitted if git was installed but the .git directory was missing.
This fix will also omit git info in case git itself is missing (unless, of course, the environment args are there).
TheKevJames pushed a commit that referenced this issue Sep 28, 2018
Addresses this comment: #174 (comment)

Previously, git info was omitted if git was installed but the .git directory was missing.
This fix will also omit git info in case git itself is missing (unless, of course, the environment args are there).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants