Skip to content

Commit a2d6787

Browse files
committed
util: move expand_path from repo/base and use it in Git class init
1 parent cf8dc25 commit a2d6787

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ Contributors are:
1919
-Timothy B. Hartman <tbhartman _at_ gmail.com>
2020
-Konstantin Popov <konstantin.popov.89 _at_ yandex.ru>
2121
-Peter Jones <pjones _at_ redhat.com>
22+
-Alexis Horgix Chotard
2223

2324
Portions derived from other open source works and are clearly marked.

git/cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
)
3232
from git.exc import CommandError
3333
from git.odict import OrderedDict
34-
from git.util import is_cygwin_git, cygpath
34+
from git.util import is_cygwin_git, cygpath, expand_path
3535

3636
from .exc import (
3737
GitCommandError,
@@ -405,7 +405,7 @@ def __init__(self, working_dir=None):
405405
It is meant to be the working tree directory if available, or the
406406
.git directory in case of bare repositories."""
407407
super(Git, self).__init__()
408-
self._working_dir = working_dir
408+
self._working_dir = expand_path(working_dir)
409409
self._git_options = ()
410410
self._persistent_git_options = []
411411

git/repo/base.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from git.objects import Submodule, RootModule, Commit
3030
from git.refs import HEAD, Head, Reference, TagReference
3131
from git.remote import Remote, add_progress, to_progress_instance
32-
from git.util import Actor, finalize_process, decygpath, hex_to_bin
32+
from git.util import Actor, finalize_process, decygpath, hex_to_bin, expand_path
3333
import os.path as osp
3434

3535
from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch, find_worktree_git_dir
@@ -50,10 +50,6 @@
5050
__all__ = ('Repo',)
5151

5252

53-
def _expand_path(p):
54-
return osp.normpath(osp.abspath(osp.expandvars(osp.expanduser(p))))
55-
56-
5753
class Repo(object):
5854
"""Represents a git repository and allows you to query references,
5955
gather commit information, generate diffs, create and clone repositories query
@@ -121,7 +117,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
121117
epath = os.getcwd()
122118
if Git.is_cygwin():
123119
epath = decygpath(epath)
124-
epath = _expand_path(epath or path or os.getcwd())
120+
epath = expand_path(epath or path or os.getcwd())
125121
if not os.path.exists(epath):
126122
raise NoSuchPathError(epath)
127123

@@ -148,7 +144,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
148144
sm_gitpath = find_worktree_git_dir(dotgit)
149145

150146
if sm_gitpath is not None:
151-
self.git_dir = _expand_path(sm_gitpath)
147+
self.git_dir = expand_path(sm_gitpath)
152148
self._working_tree_dir = curpath
153149
break
154150

@@ -867,7 +863,7 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
867863
868864
:return: ``git.Repo`` (the newly created repo)"""
869865
if path:
870-
path = _expand_path(path)
866+
path = expand_path(path)
871867
if mkdir and path and not osp.exists(path):
872868
os.makedirs(path, 0o755)
873869

git/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ def finalize_process(proc, **kwargs):
340340
## TODO: No close proc-streams??
341341
proc.wait(**kwargs)
342342

343+
344+
def expand_path(p):
345+
try:
346+
return osp.normpath(osp.abspath(osp.expandvars(osp.expanduser(p))))
347+
except:
348+
return None
349+
343350
#} END utilities
344351

345352
#{ Classes

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy