Skip to content

Commit

Permalink
Merge pull request #34 from laurentb/fix-repo-discovery
Browse files Browse the repository at this point in the history
Let git find out where the repo is
  • Loading branch information
Kenneth Reitz committed Mar 25, 2012
2 parents 5202e48 + 3416d24 commit 9e64b1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
15 changes: 0 additions & 15 deletions legit/helpers.py
Expand Up @@ -16,18 +16,3 @@
is_osx = (_platform == 'darwin')
is_win = (_platform == 'windows')
is_lin = (_platform == 'linux')


def find_path_above(*names):
"""Attempt to locate given path by searching parent dirs."""

path = '.'

while os.path.split(os.path.abspath(path))[1]:
for name in names:
joined = os.path.join(path, name)
if os.path.exists(joined):
return os.path.abspath(joined)
path = os.path.join('..', path)


11 changes: 6 additions & 5 deletions legit/scm.py
Expand Up @@ -9,13 +9,13 @@

import os
import sys
import subprocess
from collections import namedtuple
from operator import attrgetter

from git import Repo, Git
from git.exc import GitCommandError

from .helpers import find_path_above
from .settings import settings


Expand Down Expand Up @@ -208,11 +208,12 @@ def publish_branch(branch):
def get_repo():
"""Returns the current Repo, based on path."""

bare_path = find_path_above('.git')
work_path = subprocess.Popen([git, 'rev-parse', '--show-toplevel'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()[0].rstrip('\n')

if bare_path:
prelapsarian_path = os.path.split(bare_path)[0]
return Repo(prelapsarian_path)
if work_path:
return Repo(work_path)
else:
return None

Expand Down

0 comments on commit 9e64b1d

Please sign in to comment.