Skip to content

Commit 8c50ce1

Browse files
authored
Merge pull request #16 from George-Ogden/multiple-remotes
Allow Multiple Remote Branches
2 parents 816f750 + c5206d5 commit 8c50ce1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

mirror/githelper.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Never, cast
99

1010
import git
11-
from git import GitCommandError, GitError, InvalidGitRepositoryError, Tree
11+
from git import HEAD, GitCommandError, GitError, Head, InvalidGitRepositoryError, Tree
1212
from git import Repo as GitRepo
1313
from git.cmd import _AutoInterrupt as GitCmd
1414
from loguru import logger
@@ -132,9 +132,13 @@ def _clone(cls, remote: Remote, local: AbsDir) -> None:
132132
@classmethod
133133
def _sync(cls, local: GitDir) -> None:
134134
with describe(f"Pulling {cls.repo(local).remote().url} into {local}", error_level="DEBUG"):
135-
repo = cls.repo(local)
136-
[fetch_info] = repo.remote().fetch()
137-
repo.head.reset(fetch_info.commit, working_tree=True, index=True)
135+
commit = cls._fetch(local)
136+
cls.head(local).reset(commit.sha, working_tree=True, index=True)
137+
138+
@classmethod
139+
def _fetch(cls, local: GitDir) -> Commit:
140+
cls.repo(local).remote().fetch()
141+
return Commit(strict_not_none(cls.branch(local).tracking_branch()).commit.hexsha)
138142

139143
@classmethod
140144
def fresh_diff(cls, local: GitDir, file: RelFile) -> str:
@@ -167,9 +171,17 @@ def apply_patch(cls, local: GitDir, patch: str) -> None:
167171
def hash_object(cls, local: GitDir, blob: bytes) -> None:
168172
cls.run_command(local, "hash-object", "--stdin", "-w", stdin=blob)
169173

174+
@classmethod
175+
def head(cls, local: GitDir) -> HEAD:
176+
return cls.repo(local).head
177+
178+
@classmethod
179+
def branch(cls, local: GitDir) -> Head:
180+
return cls.repo(local).active_branch
181+
170182
@classmethod
171183
def commit(cls, local: GitDir) -> str:
172-
return cls.repo(local).head.commit.hexsha
184+
return cls.head(local).commit.hexsha
173185

174186
@classmethod
175187
def tree(cls, local: GitDir, commit: Commit | None = None) -> Tree:

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0
1+
0.3.1

0 commit comments

Comments
 (0)