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

shell: Fixes for windows #68

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions revup/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import re
import shutil
import tempfile
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Pattern, Tuple
Expand Down Expand Up @@ -131,8 +132,11 @@ def is_commit_hash(commit_ish: GitCommitHash) -> bool:
return re.match(RE_COMMIT_HASH, commit_ish) is not None


async def get_default_git(sh: shell.Shell) -> str:
return (await sh.sh("/usr/bin/which", "git"))[1].strip()
def get_default_git() -> str:
ret = shutil.which("git")
if not ret:
raise RevupUsageException("Could not find a 'git' binary on the current PATH.")
return ret


async def make_git(
Expand All @@ -146,7 +150,7 @@ async def make_git(
editor: str = "",
) -> "Git":
if not git_path:
git_path = await get_default_git(sh)
git_path = get_default_git()

git_ctx = Git(sh, git_path, remote_name, main_branch, base_branch_globs, keep_temp)

Expand Down
13 changes: 8 additions & 5 deletions revup/revup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
import sys
from argparse import _StoreAction, _StoreFalseAction, _StoreTrueAction
from builtins import FileNotFoundError
from contextlib import asynccontextmanager
from typing import Any, AsyncGenerator, Tuple

Expand All @@ -26,8 +27,12 @@ class HelpAction(argparse.Action):
def __call__(self, parser: Any, namespace: Any, values: Any, option_string: Any = None) -> None:
source_dir = os.path.dirname(os.path.abspath(__file__))
man_cmd = ("man", "-M", source_dir, parser.prog.split()[-1])
if subprocess.call(man_cmd) != 0:
print("Couldn't format man page, is 'man' available?")
try:
if subprocess.call(man_cmd) != 0:
print("Error in showing man page")
print(parser.format_help())
except FileNotFoundError:
print("'man' binary not found.")
print(parser.format_help())
sys.exit(0)

Expand Down Expand Up @@ -122,9 +127,7 @@ async def get_config() -> config.Config:
# There's a chicken/egg problem in getting git path from config when we need git
# to find the path of the config file. Just this once, we use the default.
sh = shell.Shell()
repo_root = (await sh.sh(await git.get_default_git(sh), "rev-parse", "--show-toplevel"))[
1
].rstrip()
repo_root = (await sh.sh(git.get_default_git(), "rev-parse", "--show-toplevel"))[1].rstrip()
conf = config.Config(config_path, os.path.join(repo_root, config_file_name))
conf.read()
return conf
Expand Down