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

adamws / kicad-git / 01125c56-a45f-40c6-bc4f-0f9618299ba7

05 Mar 2024 11:24AM UTC coverage: 91.525% (-1.3%) from 92.857%
01125c56-a45f-40c6-bc4f-0f9618299ba7

push

circleci

web-flow
Add logic to select correct git on macOS (#2)

Subprocess on macOS uses the system binaries eg Apple's Git version at `/usr/bin` by preference
unless the path is made explicit. 
Most people use a CLI package manager to use their own versions - eg git citool.
To access the user installed binary, the full path must be enumerated.

4 of 7 new or added lines in 1 file covered. (57.14%)

108 of 118 relevant lines covered (91.53%)

0.92 hits per line

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

90.91
/source/git.py
1
import platform
1✔
2
import subprocess
1✔
3
from pathlib import Path
1✔
4
from typing import Optional
1✔
5

6
if platform.system() == "Darwin":
1✔
NEW
7
    gitTool = "/opt/homebrew/bin/git "
×
NEW
8
    gitCITool = "/opt/homebrew/bin/git-citool "
×
9
else:
10
    gitTool = "git "
1✔
11
    gitCITool = "git citool"
1✔
12

13

14
def __run(command: str, cwd: Path) -> str:
1✔
15
    process = subprocess.Popen(
1✔
16
        gitTool + command,
17
        cwd=cwd,
18
        shell=True,
19
        stdout=subprocess.PIPE,
20
        stderr=subprocess.STDOUT,
21
        universal_newlines=True,
22
    )
23
    process.wait()
1✔
24
    output = ""
1✔
25
    if process.stdout:
1✔
26
        output = process.stdout.read()
1✔
27
    if process.returncode == 0:
1✔
28
        return output
1✔
29
    error = f"Error: Failed to 'git {command}', received: {output}"
1✔
30
    raise RuntimeError(error)
1✔
31

32

33
def version() -> str:
1✔
34
    return __run("version", Path("."))
1✔
35

36

37
def toplevel(path: Path) -> Optional[Path]:
1✔
38
    if path.exists():
1✔
39
        try:
1✔
40
            result = __run("rev-parse --show-toplevel", path).strip()
1✔
41
            if result:
1✔
42
                return Path(result)
1✔
43
        except RuntimeError:
1✔
44
            pass
1✔
45
    return None
1✔
46

47

48
def citool(repo_dir: Path) -> None:
1✔
NEW
49
    subprocess.Popen(gitCITool, cwd=repo_dir, shell=True)
×
50

51

52
__all__ = ["version", "toplevel", "citool"]
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