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

Don't crash due to "dubious ownership" of git dir #474

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
35 changes: 29 additions & 6 deletions src/levanter/tracker/wandb.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,33 @@ def _git_settings(self):
other_settings["code_dir"] = code_dir
other_settings["git_root"] = code_dir
# for some reason, wandb isn't populating the git commit, so we do it here
try:
repo = Repo(code_dir)
other_settings["git_commit"] = repo.head.commit.hexsha
except (NoSuchPathError, InvalidGitRepositoryError):
logger.warning(f"Could not find git repo at {code_dir}")
pass
sha = self._get_git_sha(code_dir)
if sha is not None:
other_settings["git_commit"] = sha

return other_settings

def _get_git_sha(self, code_dir) -> Optional[str]:
try:
repo = Repo(code_dir)
git_sha = repo.head.commit.hexsha
except (NoSuchPathError, InvalidGitRepositoryError):
logger.warning(f"Could not find git repo at {code_dir}")
return None
except ValueError as e:
if "SHA is empty" in str(e):
# we have another workaround, which is to use the git command line
# git --git-dir={code_dir}/.git rev-parse HEAD
import subprocess

try:
out = subprocess.run(
["git", "--git-dir", f"{code_dir}/.git", "rev-parse", "HEAD"], check=True, capture_output=True
)
git_sha = out.stdout.decode().strip()
except subprocess.CalledProcessError:
return None
else:
raise e

return git_sha
Loading