diff options
Diffstat (limited to 'git/repo/base.py')
-rw-r--r-- | git/repo/base.py | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/git/repo/base.py b/git/repo/base.py index 3bbcdb59..933c8c82 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -32,6 +32,7 @@ from gitdb.util import ( from fun import ( rev_parse, is_git_dir, + find_git_dir, touch ) @@ -55,13 +56,13 @@ class Repo(object): The following attributes are worth using: - 'working_dir' is the working directory of the git command, wich is the working tree + 'working_dir' is the working directory of the git command, which is the working tree directory if available or the .git directory in case of bare repositories 'working_tree_dir' is the working tree directory, but will raise AssertionError if we are a bare repository. - 'git_dir' is the .git repository directoy, which is always set.""" + 'git_dir' is the .git repository directory, which is always set.""" DAEMON_EXPORT_FILE = 'git-daemon-export-ok' __slots__ = ( "working_dir", "_working_tree_dir", "git_dir", "_bare", "git", "odb" ) @@ -108,8 +109,8 @@ class Repo(object): self.git_dir = curpath self._working_tree_dir = os.path.dirname(curpath) break - gitpath = join(curpath, '.git') - if is_git_dir(gitpath): + gitpath = find_git_dir(join(curpath, '.git')) + if gitpath is not None: self.git_dir = gitpath self._working_tree_dir = curpath break @@ -119,7 +120,7 @@ class Repo(object): # END while curpath if self.git_dir is None: - raise InvalidGitRepositoryError(epath) + raise InvalidGitRepositoryError(epath) self._bare = False try: @@ -375,7 +376,7 @@ class Repo(object): if rev is None: return self.head.commit else: - return self.rev_parse(str(rev)+"^0") + return self.rev_parse(unicode(rev)+"^0") def iter_trees(self, *args, **kwargs): """:return: Iterator yielding Tree objects @@ -398,7 +399,7 @@ class Repo(object): if rev is None: return self.head.commit.tree else: - return self.rev_parse(str(rev)+"^{tree}") + return self.rev_parse(unicode(rev)+"^{tree}") def iter_commits(self, rev=None, paths='', **kwargs): """A list of Commit objects representing the history of a given ref/commit @@ -498,8 +499,8 @@ class Repo(object): default_args = ('--abbrev=40', '--full-index', '--raw') if index: # diff index against HEAD - if isfile(self.index.path) and self.head.is_valid() and \ - len(self.git.diff('HEAD', '--cached', *default_args)): + if isfile(self.index.path) and \ + len(self.git.diff('--cached', *default_args)): return True # END index handling if working_tree: @@ -512,35 +513,33 @@ class Repo(object): return True # END untracked files return False - + @property def untracked_files(self): """ :return: list(str,...) - - Files currently untracked as they have not been staged yet. Paths + + Files currently untracked as they have not been staged yet. Paths are relative to the current working directory of the git command. - + :note: ignored files will not appear here, i.e. files mentioned in .gitignore""" # make sure we get all files, no only untracked directores - proc = self.git.status(untracked_files=True, as_process=True) - stream = iter(proc.stdout) + proc = self.git.status(porcelain=True, + untracked_files=True, + as_process=True) + # Untracked files preffix in porcelain mode + prefix = "?? " untracked_files = list() - for line in stream: - if not line.startswith("# Untracked files:"): + for line in proc.stdout: + if not line.startswith(prefix): continue - # skip two lines - stream.next() - stream.next() - - for untracked_info in stream: - if not untracked_info.startswith("#\t"): - break - untracked_files.append(untracked_info.replace("#\t", "").rstrip()) - # END for each utracked info line - # END for each line + filename = line[len(prefix):].rstrip('\n') + # Special characters are escaped + if filename[0] == filename[-1] == '"': + filename = filename[1:-1].decode('string_escape') + untracked_files.append(filename) return untracked_files @property |