• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adamws / kicad-git / a1847925-b070-4a3d-af64-f70d414c46c8

29 Apr 2024 06:49PM UTC coverage: 92.248% (-2.0%) from 94.215%
a1847925-b070-4a3d-af64-f70d414c46c8

push

circleci

adamws
Handle spaces in executable paths

Fixes #5

5 of 9 new or added lines in 1 file covered. (55.56%)

119 of 129 relevant lines covered (92.25%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.13
/source/git.py
1
import configparser
1✔
2
import os
1✔
3
import platform
1✔
4
import shlex
1✔
5
import subprocess
1✔
6
import sys
1✔
7
from pathlib import Path
1✔
8
from typing import Optional
1✔
9

10
if platform.system() == "Darwin":
1✔
11
    DEFAULT_CONFIG = """[paths]
×
12
        git = /opt/homebrew/bin/git
13
        git_gui = /opt/homebrew/bin/git gui"""
14
else:
15
    DEFAULT_CONFIG = """[paths]
1✔
16
        git = git
17
        git_gui = git gui"""
18

19
config = configparser.ConfigParser()
1✔
20
config.read_string(DEFAULT_CONFIG)
1✔
21
config.read(os.path.dirname(__file__) + "/config.ini")
1✔
22

23
git: str = config["paths"]["git"]
1✔
24
git_gui: str = config["paths"]["git_gui"]
1✔
25

26

27
def __run(command: str, cwd: Path) -> str:
1✔
28
    args = f"{git} {command}"
1✔
29
    if sys.platform != "win32":
1✔
30
        args = shlex.split(args)
1✔
31
    process = subprocess.Popen(
1✔
32
        args,
33
        cwd=cwd,
34
        stdout=subprocess.PIPE,
35
        stderr=subprocess.STDOUT,
36
        universal_newlines=True,
37
    )
38
    process.wait()
1✔
39
    output = ""
1✔
40
    if process.stdout:
1✔
41
        output = process.stdout.read()
1✔
42
    if process.returncode == 0:
1✔
43
        return output
1✔
44
    error = f"Error: Failed to '{git} {command}', received: {output}"
1✔
45
    raise RuntimeError(error)
1✔
46

47

48
def version() -> str:
1✔
49
    return __run("version", Path("."))
1✔
50

51

52
def toplevel(path: Path) -> Optional[Path]:
1✔
53
    if path.exists():
1✔
54
        try:
1✔
55
            result = __run("rev-parse --show-toplevel", path).strip()
1✔
56
            if result:
1✔
57
                return Path(result)
1✔
58
        except RuntimeError:
1✔
59
            pass
1✔
60
    return None
1✔
61

62

63
def guitool(repo_dir: Path) -> None:
1✔
NEW
64
    args = git_gui
×
NEW
65
    if sys.platform != "win32":
×
NEW
66
        args = shlex.split(args)
×
NEW
67
    subprocess.Popen(args, cwd=repo_dir)
×
68

69

70
__all__ = ["version", "toplevel", "guitool"]
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc