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

support https git remotes in upload #516

Merged
merged 3 commits into from
Jan 7, 2025
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tach"
version = "0.19.2"
version = "0.19.3"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ If you use the [pre-commit framework](https://github.com/pre-commit/pre-commit),
```yaml
repos:
- repo: https://github.com/gauge-sh/tach-pre-commit
rev: v0.19.2 # change this to the latest tag!
rev: v0.19.3 # change this to the latest tag!
hooks:
- id: tach
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tach"
version = "0.19.2"
version = "0.19.3"
authors = [
{ name = "Caelean Barnes", email = "[email protected]" },
{ name = "Evan Doyle", email = "[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion python/tach/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

__version__: str = "0.19.2"
__version__: str = "0.19.3"

__all__ = ["__version__"]
59 changes: 55 additions & 4 deletions python/tach/filesystem/git_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,58 @@ def _get_commit(repo: Repo) -> str:
return repo.head.commit.hexsha


def _get_owner_and_repo_name(repo_url: str) -> tuple[str, str]:
"""
Parse a git URL to extract owner and repo names, handling cases where
either might contain slashes.

Strategy:
1. For HTTPS URLs, everything after the domain and before the last segment is the owner
2. For SSH URLs, everything after the colon and before the last segment is the owner
3. The last segment (minus .git) is always the repo name

Args:
url: Git remote URL (HTTPS or SSH format)

Returns:
Tuple of (owner, repo)

Examples:
>>> _get_owner_and_repo_name("https://github.com/apache/spark/spark-connector.git")
('apache/spark', 'spark-connector')
>>> _get_owner_and_repo_name("[email protected]:facebook/react-native/docs.git")
('facebook/react-native', 'docs')
"""
# Remove .git suffix and trailing slashes
url = repo_url.rstrip(".git").rstrip("/")

if url.startswith("https://"):
# HTTPS URL format
# Remove https:// prefix and split by /
parts = url[8:].split("/")
# First part is domain (e.g., github.com)
# Last part is repo name
repo = parts[-1]
# Everything between domain and repo is owner
owner = "/".join(parts[1:-1])
else:
# SSH URL format
# Split at the colon
parts = url.split(":")
if len(parts) != 2:
raise TachError(f"Invalid SSH URL format: {url}")
path_parts = parts[1].split("/")
# Last part is repo name
repo = path_parts[-1]
# Everything else is owner
owner = "/".join(path_parts[:-1])

if not owner or not repo:
raise TachError(f"Failed to parse owner or repo from URL: {url}")

return owner, repo


def get_current_branch_info(
project_root: Path, allow_dirty: bool = False
) -> GitBranchInfo:
Expand All @@ -69,15 +121,14 @@ def get_current_branch_info(
)

try:
# TODO: support slashes or org names
url_parts = repo.remotes.origin.url.split("/")
repo_name = url_parts[-1].replace(".git", "")
owner_name = url_parts[0].split(":")[-1]
url = repo.remotes.origin.url
owner_name, repo_name = _get_owner_and_repo_name(url)
config_reader = repo.config_reader()
user_name = str(config_reader.get_value("user", "name", default=""))
email = str(config_reader.get_value("user", "email", default=""))
branch = _get_branch_name(repo)
commit = _get_commit(repo)

except Exception as e:
raise TachError(f"Failed to determine current branch information!\nError: {e}")

Expand Down