question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

get_remote_url not compatible with new version of Git ?

See original GitHub issue

search you tried in the issue tracker

get_remote_url

describe your issue

When using pre-commit hook https://github.com/zricethezav/gitleaks, I faced an issue during the creation of the env issue.

I am using :

git --version
git version 2.37.3

It seems that with the recent version of git, the path to the config need to be set: git config -f .git/config --get remote.origin.url

https://github.com/pre-commit/pre-commit/blob/028efcbd879ccdac7514ea4334462841bb0ca2c0/pre_commit/git.py#L96

I did a test and the following fix the issue:

def get_remote_url(git_root: str) -> str:
    _, out, _ = cmd_output('git', 'config', '-f', git_root+'/.git/config', 'remote.origin.url', cwd=git_root)
    return out.strip()

I am sure there is a better way to fix this issue. Any idea ?

pre-commit --version

pre-commit 2.20.0

.pre-commit-config.yaml

default_language_version:
  python: python3.10

default_stages: [commit, push]


repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.3.0
    hooks:
      - id: end-of-file-fixer
        exclude: .*ipynb
      - id: trailing-whitespace
        args: ["--markdown-linebreak-ext=md,markdown"]
      - id: check-added-large-files
        args: ["--maxkb=1024"]
      - id: check-ast
      - id: check-docstring-first
      - id: check-json
      - id: check-toml
      - id: check-yaml
      - id: check-executables-have-shebangs
      - id: check-shebang-scripts-are-executable
      - id: name-tests-test
      - id: no-commit-to-branch
        args: [--branch, main]
      - id: detect-private-key
      - id: mixed-line-ending

  - repo: https://github.com/zricethezav/gitleaks
    rev: v8.13.0
    hooks:
      - id: gitleaks

~/.cache/pre-commit/pre-commit.log (if present)

pre-commit version: 2.20.0
git --version: git version 2.37.3
sys.version:
    3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:35:26) [GCC 10.4.0]
sys.executable: /opt/conda/envs/jupyter-notebook/bin/python
os.name: posix
sys.platform: linux

error information

An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'config', 'remote.origin.url')
return code: 1
expected return code: 0
stdout: (none)
stderr: (none)
Traceback (most recent call last):
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/main.py", line 386, in main
    return run(args.config, store, args)
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/commands/run.py", line 424, in run
    install_hook_envs(to_install, store)
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/repository.py", line 79, in _hook_install
    lang.install_environment(
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/languages/golang.py", line 69, in install_environment
    remote = git.get_remote_url(prefix.prefix_dir)
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/git.py", line 97, in get_remote_url
    _, out, _ = cmd_output('git', 'config', 'remote.origin.url', cwd=git_root)
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/util.py", line 152, in cmd_output
    returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)
  File "/opt/conda/envs/jupyter-notebook/lib/python3.10/site-packages/pre_commit/util.py", line 146, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'config', 'remote.origin.url')
return code: 1
expected return code: 0
stdout: (none)
stderr: (none)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tarradecommented, Oct 4, 2022

ok, problem fixed. GIT_CONFIG should no be defined at all, having an empty value will create the issue as well. Closing

1reaction
tarradecommented, Oct 4, 2022

Right it seems to be problematic. I did a test without before but I should have done something wrong since the issue was still present. I also misunderstood the git doc. OK, I will clean my setup and try again to be 100% sure and then close this ticket. Thanks for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

github - How to determine the URL that a local Git repository ...
To obtain only the remote URL: git config --get remote.origin.url. If you require full output, and you are on a network that can...
Read more >
Git show remote url-How can I determine the URL that a local ...
This answer appears in google search result for "git get remote url" and is wrong. You do not need to know configuration tree...
Read more >
2.5 Git Basics - Working with Remotes
Managing remote repositories includes knowing how to add remote repositories, remove remotes that are no longer valid, manage various remote branches and define ......
Read more >
Downloads - Git SCM
If you already have Git installed, you can get the latest development version via Git itself: git clone https://github.com/git/git.
Read more >
1.5 Getting Started - Installing Git
Even if it's already installed, it's probably a good idea to update to the latest version. You can either install it as a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found