Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0210e39

Browse files
committedOct 16, 2016
src: import os.path as osp
1 parent a2d248b commit 0210e39

24 files changed

+361
-332
lines changed
 

‎git/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
# flake8: noqa
77
#@PydevCodeAnalysisIgnore
8+
import inspect
89
import os
910
import sys
10-
import inspect
11+
12+
import os.path as osp
13+
1114

1215
__version__ = 'git'
1316

@@ -16,7 +19,7 @@
1619
def _init_externals():
1720
"""Initialize external projects by putting them into the path"""
1821
if __version__ == 'git':
19-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'ext', 'gitdb'))
22+
sys.path.insert(0, osp.join(osp.dirname(__file__), 'ext', 'gitdb'))
2023

2124
try:
2225
import gitdb

‎git/config.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@
66
"""Module containing module parser implementation able to properly read and write
77
configuration files"""
88

9-
import re
10-
try:
11-
import ConfigParser as cp
12-
except ImportError:
13-
# PY3
14-
import configparser as cp
9+
import abc
10+
from functools import wraps
1511
import inspect
1612
import logging
17-
import abc
1813
import os
14+
import re
1915

20-
from functools import wraps
21-
22-
from git.odict import OrderedDict
23-
from git.util import LockFile
2416
from git.compat import (
2517
string_types,
2618
FileType,
@@ -29,6 +21,18 @@
2921
with_metaclass,
3022
PY3
3123
)
24+
from git.odict import OrderedDict
25+
from git.util import LockFile
26+
27+
import os.path as osp
28+
29+
30+
try:
31+
import ConfigParser as cp
32+
except ImportError:
33+
# PY3
34+
import configparser as cp
35+
3236

3337
__all__ = ('GitConfigParser', 'SectionConstraint')
3438

@@ -408,15 +412,15 @@ def read(self):
408412
if self._has_includes():
409413
for _, include_path in self.items('include'):
410414
if include_path.startswith('~'):
411-
include_path = os.path.expanduser(include_path)
412-
if not os.path.isabs(include_path):
415+
include_path = osp.expanduser(include_path)
416+
if not osp.isabs(include_path):
413417
if not file_ok:
414418
continue
415419
# end ignore relative paths if we don't know the configuration file path
416-
assert os.path.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
417-
include_path = os.path.join(os.path.dirname(file_path), include_path)
420+
assert osp.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
421+
include_path = osp.join(osp.dirname(file_path), include_path)
418422
# end make include path absolute
419-
include_path = os.path.normpath(include_path)
423+
include_path = osp.normpath(include_path)
420424
if include_path in seen or not os.access(include_path, os.R_OK):
421425
continue
422426
seen.add(include_path)

‎git/index/base.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,36 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
import tempfile
7-
import os
8-
import sys
9-
import subprocess
106
import glob
117
from io import BytesIO
12-
8+
import os
139
from stat import S_ISLNK
10+
import subprocess
11+
import sys
12+
import tempfile
1413

15-
from .typ import (
16-
BaseIndexEntry,
17-
IndexEntry,
18-
)
19-
20-
from .util import (
21-
TemporaryFileSwap,
22-
post_clear_cache,
23-
default_index,
24-
git_working_dir
14+
from git.compat import (
15+
izip,
16+
xrange,
17+
string_types,
18+
force_bytes,
19+
defenc,
20+
mviter,
21+
is_win
2522
)
26-
27-
import git.diff as diff
2823
from git.exc import (
2924
GitCommandError,
3025
CheckoutError,
3126
InvalidGitRepositoryError
3227
)
33-
3428
from git.objects import (
3529
Blob,
3630
Submodule,
3731
Tree,
3832
Object,
3933
Commit,
4034
)
41-
4235
from git.objects.util import Serializable
43-
from git.compat import (
44-
izip,
45-
xrange,
46-
string_types,
47-
force_bytes,
48-
defenc,
49-
mviter,
50-
is_win
51-
)
52-
5336
from git.util import (
5437
LazyMixin,
5538
LockedFD,
@@ -58,6 +41,12 @@
5841
to_native_path_linux,
5942
unbare_repo
6043
)
44+
from gitdb.base import IStream
45+
from gitdb.db import MemoryDB
46+
from gitdb.util import to_bin_sha
47+
48+
import git.diff as diff
49+
import os.path as osp
6150

6251
from .fun import (
6352
entry_key,
@@ -69,10 +58,17 @@
6958
S_IFGITLINK,
7059
run_commit_hook
7160
)
61+
from .typ import (
62+
BaseIndexEntry,
63+
IndexEntry,
64+
)
65+
from .util import (
66+
TemporaryFileSwap,
67+
post_clear_cache,
68+
default_index,
69+
git_working_dir
70+
)
7271

73-
from gitdb.base import IStream
74-
from gitdb.db import MemoryDB
75-
from gitdb.util import to_bin_sha
7672

7773
__all__ = ('IndexFile', 'CheckoutError')
7874

@@ -354,7 +350,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
354350
index.entries # force it to read the file as we will delete the temp-file
355351
del(index_handler) # release as soon as possible
356352
finally:
357-
if os.path.exists(tmp_index):
353+
if osp.exists(tmp_index):
358354
os.remove(tmp_index)
359355
# END index merge handling
360356

@@ -374,8 +370,8 @@ def raise_exc(e):
374370
rs = r + os.sep
375371
for path in paths:
376372
abs_path = path
377-
if not os.path.isabs(abs_path):
378-
abs_path = os.path.join(r, path)
373+
if not osp.isabs(abs_path):
374+
abs_path = osp.join(r, path)
379375
# END make absolute path
380376

381377
try:
@@ -407,7 +403,7 @@ def raise_exc(e):
407403
for root, dirs, files in os.walk(abs_path, onerror=raise_exc): # @UnusedVariable
408404
for rela_file in files:
409405
# add relative paths only
410-
yield os.path.join(root.replace(rs, ''), rela_file)
406+
yield osp.join(root.replace(rs, ''), rela_file)
411407
# END for each file in subdir
412408
# END for each subdirectory
413409
except OSError:
@@ -569,7 +565,7 @@ def _process_diff_args(self, args):
569565
def _to_relative_path(self, path):
570566
""":return: Version of path relative to our git directory or raise ValueError
571567
if it is not within our git direcotory"""
572-
if not os.path.isabs(path):
568+
if not osp.isabs(path):
573569
return path
574570
if self.repo.bare:
575571
raise InvalidGitRepositoryError("require non-bare repository")
@@ -617,12 +613,12 @@ def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
617613
entries_added = list()
618614
if path_rewriter:
619615
for path in paths:
620-
if os.path.isabs(path):
616+
if osp.isabs(path):
621617
abspath = path
622618
gitrelative_path = path[len(self.repo.working_tree_dir) + 1:]
623619
else:
624620
gitrelative_path = path
625-
abspath = os.path.join(self.repo.working_tree_dir, gitrelative_path)
621+
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
626622
# end obtain relative and absolute paths
627623

628624
blob = Blob(self.repo, Blob.NULL_BIN_SHA,

‎git/index/fun.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Contains standalone functions to accompany the index implementation and make it
22
# more versatile
33
# NOTE: Autodoc hates it if this is a docstring
4+
from io import BytesIO
5+
import os
46
from stat import (
57
S_IFDIR,
68
S_IFLNK,
@@ -9,13 +11,18 @@
911
S_IFMT,
1012
S_IFREG,
1113
)
12-
13-
from io import BytesIO
14-
import os
1514
import subprocess
1615

17-
from git.util import IndexFileSHA1Writer, finalize_process
1816
from git.cmd import PROC_CREATIONFLAGS, handle_process_output
17+
from git.compat import (
18+
PY3,
19+
defenc,
20+
force_text,
21+
force_bytes,
22+
is_posix,
23+
safe_encode,
24+
safe_decode,
25+
)
1926
from git.exc import (
2027
UnmergedEntriesError,
2128
HookExecutionError
@@ -25,30 +32,23 @@
2532
traverse_tree_recursive,
2633
traverse_trees_recursive
2734
)
35+
from git.util import IndexFileSHA1Writer, finalize_process
36+
from gitdb.base import IStream
37+
from gitdb.typ import str_tree_type
38+
39+
import os.path as osp
2840

2941
from .typ import (
3042
BaseIndexEntry,
3143
IndexEntry,
3244
CE_NAMEMASK,
3345
CE_STAGESHIFT
3446
)
35-
3647
from .util import (
3748
pack,
3849
unpack
3950
)
4051

41-
from gitdb.base import IStream
42-
from gitdb.typ import str_tree_type
43-
from git.compat import (
44-
PY3,
45-
defenc,
46-
force_text,
47-
force_bytes,
48-
is_posix,
49-
safe_encode,
50-
safe_decode,
51-
)
5252

5353
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
5454
CE_NAMEMASK_INV = ~CE_NAMEMASK
@@ -59,7 +59,7 @@
5959

6060
def hook_path(name, git_dir):
6161
""":return: path to the given named hook in the given git repository directory"""
62-
return os.path.join(git_dir, 'hooks', name)
62+
return osp.join(git_dir, 'hooks', name)
6363

6464

6565
def run_commit_hook(name, index):

‎git/index/util.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
"""Module containing index utilities"""
2+
from functools import wraps
3+
import os
24
import struct
35
import tempfile
4-
import os
5-
6-
from functools import wraps
76

87
from git.compat import is_win
98

9+
import os.path as osp
10+
11+
1012
__all__ = ('TemporaryFileSwap', 'post_clear_cache', 'default_index', 'git_working_dir')
1113

1214
#{ Aliases
@@ -32,8 +34,8 @@ def __init__(self, file_path):
3234
pass
3335

3436
def __del__(self):
35-
if os.path.isfile(self.tmp_file_path):
36-
if is_win and os.path.exists(self.file_path):
37+
if osp.isfile(self.tmp_file_path):
38+
if is_win and osp.exists(self.file_path):
3739
os.remove(self.file_path)
3840
os.rename(self.tmp_file_path, self.file_path)
3941
# END temp file exists

‎git/objects/submodule/base.py

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
from .util import (
2-
mkhead,
3-
sm_name,
4-
sm_section,
5-
SubmoduleConfigParser,
6-
find_first_remote_branch
7-
)
8-
from git.objects.util import Traversable
9-
from io import BytesIO # need a dict to set bloody .name field
10-
from git.util import (
11-
Iterable,
12-
join_path_native,
13-
to_native_path_linux,
14-
RemoteProgress,
15-
rmtree,
16-
unbare_repo
17-
)
1+
# need a dict to set bloody .name field
2+
from io import BytesIO
3+
import logging
4+
import os
5+
import stat
6+
from unittest.case import SkipTest
7+
import uuid
188

9+
import git
10+
from git.cmd import Git
11+
from git.compat import (
12+
string_types,
13+
defenc,
14+
is_win,
15+
)
1916
from git.config import (
2017
SectionConstraint,
2118
GitConfigParser,
@@ -26,22 +23,28 @@
2623
NoSuchPathError,
2724
RepositoryDirtyError
2825
)
29-
from git.compat import (
30-
string_types,
31-
defenc,
32-
is_win,
26+
from git.objects.base import IndexObject, Object
27+
from git.objects.util import Traversable
28+
from git.util import (
29+
Iterable,
30+
join_path_native,
31+
to_native_path_linux,
32+
RemoteProgress,
33+
rmtree,
34+
unbare_repo
3335
)
36+
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
3437

35-
import stat
36-
import git
38+
import os.path as osp
39+
40+
from .util import (
41+
mkhead,
42+
sm_name,
43+
sm_section,
44+
SubmoduleConfigParser,
45+
find_first_remote_branch
46+
)
3747

38-
import os
39-
import logging
40-
import uuid
41-
from unittest.case import SkipTest
42-
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
43-
from git.objects.base import IndexObject, Object
44-
from git.cmd import Git
4548

4649
__all__ = ["Submodule", "UpdateProgress"]
4750

@@ -120,7 +123,7 @@ def _set_cache_(self, attr):
120123
self.path = reader.get_value('path')
121124
except cp.NoSectionError:
122125
raise ValueError("This submodule instance does not exist anymore in '%s' file"
123-
% os.path.join(self.repo.working_tree_dir, '.gitmodules'))
126+
% osp.join(self.repo.working_tree_dir, '.gitmodules'))
124127
# end
125128
self._url = reader.get_value('url')
126129
# git-python extension values - optional
@@ -181,7 +184,7 @@ def _config_parser(cls, repo, parent_commit, read_only):
181184
# end hanlde parent_commit
182185

183186
if not repo.bare and parent_matches_head:
184-
fp_module = os.path.join(repo.working_tree_dir, cls.k_modules_file)
187+
fp_module = osp.join(repo.working_tree_dir, cls.k_modules_file)
185188
else:
186189
assert parent_commit is not None, "need valid parent_commit in bare repositories"
187190
try:
@@ -229,9 +232,9 @@ def _config_parser_constrained(self, read_only):
229232
@classmethod
230233
def _module_abspath(cls, parent_repo, path, name):
231234
if cls._need_gitfile_submodules(parent_repo.git):
232-
return os.path.join(parent_repo.git_dir, 'modules', name)
235+
return osp.join(parent_repo.git_dir, 'modules', name)
233236
else:
234-
return os.path.join(parent_repo.working_tree_dir, path)
237+
return osp.join(parent_repo.working_tree_dir, path)
235238
# end
236239

237240
@classmethod
@@ -246,10 +249,10 @@ def _clone_repo(cls, repo, url, path, name, **kwargs):
246249
module_checkout_path = module_abspath
247250
if cls._need_gitfile_submodules(repo.git):
248251
kwargs['separate_git_dir'] = module_abspath
249-
module_abspath_dir = os.path.dirname(module_abspath)
250-
if not os.path.isdir(module_abspath_dir):
252+
module_abspath_dir = osp.dirname(module_abspath)
253+
if not osp.isdir(module_abspath_dir):
251254
os.makedirs(module_abspath_dir)
252-
module_checkout_path = os.path.join(repo.working_tree_dir, path)
255+
module_checkout_path = osp.join(repo.working_tree_dir, path)
253256
# end
254257

255258
clone = git.Repo.clone_from(url, module_checkout_path, **kwargs)
@@ -267,7 +270,7 @@ def _to_relative_path(cls, parent_repo, path):
267270
path = path[:-1]
268271
# END handle trailing slash
269272

270-
if os.path.isabs(path):
273+
if osp.isabs(path):
271274
working_tree_linux = to_native_path_linux(parent_repo.working_tree_dir)
272275
if not path.startswith(working_tree_linux):
273276
raise ValueError("Submodule checkout path '%s' needs to be within the parents repository at '%s'"
@@ -291,18 +294,18 @@ def _write_git_file_and_module_config(cls, working_tree_dir, module_abspath):
291294
:param working_tree_dir: directory to write the .git file into
292295
:param module_abspath: absolute path to the bare repository
293296
"""
294-
git_file = os.path.join(working_tree_dir, '.git')
295-
rela_path = os.path.relpath(module_abspath, start=working_tree_dir)
297+
git_file = osp.join(working_tree_dir, '.git')
298+
rela_path = osp.relpath(module_abspath, start=working_tree_dir)
296299
if is_win:
297-
if os.path.isfile(git_file):
300+
if osp.isfile(git_file):
298301
os.remove(git_file)
299302
with open(git_file, 'wb') as fp:
300303
fp.write(("gitdir: %s" % rela_path).encode(defenc))
301304

302-
with GitConfigParser(os.path.join(module_abspath, 'config'),
305+
with GitConfigParser(osp.join(module_abspath, 'config'),
303306
read_only=False, merge_includes=False) as writer:
304307
writer.set_value('core', 'worktree',
305-
to_native_path_linux(os.path.relpath(working_tree_dir, start=module_abspath)))
308+
to_native_path_linux(osp.relpath(working_tree_dir, start=module_abspath)))
306309

307310
#{ Edit Interface
308311

@@ -501,7 +504,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False, progress=
501504

502505
# there is no git-repository yet - but delete empty paths
503506
checkout_module_abspath = self.abspath
504-
if not dry_run and os.path.isdir(checkout_module_abspath):
507+
if not dry_run and osp.isdir(checkout_module_abspath):
505508
try:
506509
os.rmdir(checkout_module_abspath)
507510
except OSError:
@@ -671,7 +674,7 @@ def move(self, module_path, configuration=True, module=True):
671674
# END handle no change
672675

673676
module_checkout_abspath = join_path_native(self.repo.working_tree_dir, module_checkout_path)
674-
if os.path.isfile(module_checkout_abspath):
677+
if osp.isfile(module_checkout_abspath):
675678
raise ValueError("Cannot move repository onto a file: %s" % module_checkout_abspath)
676679
# END handle target files
677680

@@ -684,12 +687,12 @@ def move(self, module_path, configuration=True, module=True):
684687

685688
# remove existing destination
686689
if module:
687-
if os.path.exists(module_checkout_abspath):
690+
if osp.exists(module_checkout_abspath):
688691
if len(os.listdir(module_checkout_abspath)):
689692
raise ValueError("Destination module directory was not empty")
690693
# END handle non-emptiness
691694

692-
if os.path.islink(module_checkout_abspath):
695+
if osp.islink(module_checkout_abspath):
693696
os.remove(module_checkout_abspath)
694697
else:
695698
os.rmdir(module_checkout_abspath)
@@ -704,11 +707,11 @@ def move(self, module_path, configuration=True, module=True):
704707
# move the module into place if possible
705708
cur_path = self.abspath
706709
renamed_module = False
707-
if module and os.path.exists(cur_path):
710+
if module and osp.exists(cur_path):
708711
os.renames(cur_path, module_checkout_abspath)
709712
renamed_module = True
710713

711-
if os.path.isfile(os.path.join(module_checkout_abspath, '.git')):
714+
if osp.isfile(osp.join(module_checkout_abspath, '.git')):
712715
module_abspath = self._module_abspath(self.repo, self.path, self.name)
713716
self._write_git_file_and_module_config(module_checkout_abspath, module_abspath)
714717
# end handle git file rewrite
@@ -804,11 +807,11 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
804807
# state. Delete the .git folders last, start with the submodules first
805808
mp = self.abspath
806809
method = None
807-
if os.path.islink(mp):
810+
if osp.islink(mp):
808811
method = os.remove
809-
elif os.path.isdir(mp):
812+
elif osp.isdir(mp):
810813
method = rmtree
811-
elif os.path.exists(mp):
814+
elif osp.exists(mp):
812815
raise AssertionError("Cannot forcibly delete repository as it was neither a link, nor a directory")
813816
# END handle brutal deletion
814817
if not dry_run:
@@ -865,7 +868,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
865868
# END delete tree if possible
866869
# END handle force
867870

868-
if not dry_run and os.path.isdir(git_dir):
871+
if not dry_run and osp.isdir(git_dir):
869872
self._clear_cache()
870873
try:
871874
rmtree(git_dir)

‎git/refs/symbolic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import os
22

3+
from git.compat import (
4+
string_types,
5+
defenc
6+
)
37
from git.objects import Object, Commit
48
from git.util import (
59
join_path,
610
join_path_native,
711
to_native_path_linux,
812
assure_directory_exists
913
)
10-
1114
from gitdb.exc import (
1215
BadObject,
1316
BadName
@@ -22,13 +25,12 @@
2225
hex_to_bin,
2326
LockedFD
2427
)
25-
from git.compat import (
26-
string_types,
27-
defenc
28-
)
28+
29+
import os.path as osp
2930

3031
from .log import RefLog
3132

33+
3234
__all__ = ["SymbolicReference"]
3335

3436

@@ -458,7 +460,7 @@ def delete(cls, repo, path):
458460

459461
# delete the reflog
460462
reflog_path = RefLog.path(cls(repo, full_ref_path))
461-
if os.path.isfile(reflog_path):
463+
if osp.isfile(reflog_path):
462464
os.remove(reflog_path)
463465
# END remove reflog
464466

‎git/repo/base.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
import re
1111
import sys
1212

13-
from gitdb.util import (
14-
join,
15-
isfile,
16-
hex_to_bin
17-
)
18-
1913
from git.cmd import (
2014
Git,
2115
handle_process_output
@@ -36,6 +30,13 @@
3630
from git.refs import HEAD, Head, Reference, TagReference
3731
from git.remote import Remote, add_progress, to_progress_instance
3832
from git.util import Actor, finalize_process, decygpath
33+
from gitdb.util import (
34+
join,
35+
isfile,
36+
hex_to_bin
37+
)
38+
39+
import os.path as osp
3940

4041
from .fun import rev_parse, is_git_dir, find_git_dir, touch
4142

@@ -54,7 +55,7 @@
5455

5556

5657
def _expand_path(p):
57-
return os.path.abspath(os.path.expandvars(os.path.expanduser(p)))
58+
return osp.abspath(osp.expandvars(osp.expanduser(p)))
5859

5960

6061
class Repo(object):
@@ -100,7 +101,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
100101
repo = Repo("$REPOSITORIES/Development/git-python.git")
101102
102103
In *Cygwin*, path may be a `'cygdrive/...'` prefixed path.
103-
104+
104105
:param odbt:
105106
Object DataBase type - a type which is constructed by providing
106107
the directory containing the database objects, i.e. .git/objects. It will
@@ -118,7 +119,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
118119

119120
epath = _expand_path(path or os.getcwd())
120121
self.git = None # should be set for __del__ not to fail in case we raise
121-
if not os.path.exists(epath):
122+
if not osp.exists(epath):
122123
raise NoSuchPathError(epath)
123124

124125
self.working_dir = None
@@ -128,24 +129,24 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
128129

129130
# walk up the path to find the .git dir
130131
while curpath:
131-
# ABOUT os.path.NORMPATH
132+
# ABOUT osp.NORMPATH
132133
# It's important to normalize the paths, as submodules will otherwise initialize their
133134
# repo instances with paths that depend on path-portions that will not exist after being
134135
# removed. It's just cleaner.
135136
if is_git_dir(curpath):
136-
self.git_dir = os.path.normpath(curpath)
137-
self._working_tree_dir = os.path.dirname(self.git_dir)
137+
self.git_dir = osp.normpath(curpath)
138+
self._working_tree_dir = osp.dirname(self.git_dir)
138139
break
139140

140141
gitpath = find_git_dir(join(curpath, '.git'))
141142
if gitpath is not None:
142-
self.git_dir = os.path.normpath(gitpath)
143+
self.git_dir = osp.normpath(gitpath)
143144
self._working_tree_dir = curpath
144145
break
145146

146147
if not search_parent_directories:
147148
break
148-
curpath, dummy = os.path.split(curpath)
149+
curpath, dummy = osp.split(curpath)
149150
if not dummy:
150151
break
151152
# END while curpath
@@ -361,12 +362,12 @@ def _get_config_path(self, config_level):
361362
if config_level == "system":
362363
return "/etc/gitconfig"
363364
elif config_level == "user":
364-
config_home = os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.environ.get("HOME", '~'), ".config")
365-
return os.path.normpath(os.path.expanduser(join(config_home, "git", "config")))
365+
config_home = os.environ.get("XDG_CONFIG_HOME") or osp.join(os.environ.get("HOME", '~'), ".config")
366+
return osp.normpath(osp.expanduser(join(config_home, "git", "config")))
366367
elif config_level == "global":
367-
return os.path.normpath(os.path.expanduser("~/.gitconfig"))
368+
return osp.normpath(osp.expanduser("~/.gitconfig"))
368369
elif config_level == "repository":
369-
return os.path.normpath(join(self.git_dir, "config"))
370+
return osp.normpath(join(self.git_dir, "config"))
370371

371372
raise ValueError("Invalid configuration level: %r" % config_level)
372373

@@ -511,11 +512,11 @@ def is_ancestor(self, ancestor_rev, rev):
511512

512513
def _get_daemon_export(self):
513514
filename = join(self.git_dir, self.DAEMON_EXPORT_FILE)
514-
return os.path.exists(filename)
515+
return osp.exists(filename)
515516

516517
def _set_daemon_export(self, value):
517518
filename = join(self.git_dir, self.DAEMON_EXPORT_FILE)
518-
fileexists = os.path.exists(filename)
519+
fileexists = osp.exists(filename)
519520
if value and not fileexists:
520521
touch(filename)
521522
elif not value and fileexists:
@@ -532,7 +533,7 @@ def _get_alternates(self):
532533
:return: list of strings being pathnames of alternates"""
533534
alternates_path = join(self.git_dir, 'objects', 'info', 'alternates')
534535

535-
if os.path.exists(alternates_path):
536+
if osp.exists(alternates_path):
536537
with open(alternates_path, 'rb') as f:
537538
alts = f.read().decode(defenc)
538539
return alts.strip().splitlines()
@@ -841,7 +842,7 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
841842
:return: ``git.Repo`` (the newly created repo)"""
842843
if path:
843844
path = _expand_path(path)
844-
if mkdir and path and not os.path.exists(path):
845+
if mkdir and path and not osp.exists(path):
845846
os.makedirs(path, 0o755)
846847

847848
# git command automatically chdir into the directory
@@ -879,7 +880,7 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
879880

880881
# our git command could have a different working dir than our actual
881882
# environment, hence we prepend its working dir if required
882-
if not os.path.isabs(path) and git.working_dir:
883+
if not osp.isabs(path) and git.working_dir:
883884
path = join(git._working_dir, path)
884885

885886
# adjust remotes - there may be operating systems which use backslashes,
@@ -958,7 +959,7 @@ def has_separate_working_tree(self):
958959
"""
959960
if self.bare:
960961
return False
961-
return os.path.isfile(os.path.join(self.working_tree_dir, '.git'))
962+
return osp.isfile(osp.join(self.working_tree_dir, '.git'))
962963

963964
rev_parse = rev_parse
964965

‎git/repo/fun.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
import os
33
from string import digits
44

5+
from git.compat import xrange
6+
from git.exc import WorkTreeRepositoryUnsupported
7+
from git.objects import Object
8+
from git.refs import SymbolicReference
59
from gitdb.exc import (
610
BadObject,
711
BadName,
812
)
9-
from git.refs import SymbolicReference
10-
from git.objects import Object
1113
from gitdb.util import (
1214
join,
1315
isdir,
@@ -16,8 +18,8 @@
1618
hex_to_bin,
1719
bin_to_hex
1820
)
19-
from git.exc import WorkTreeRepositoryUnsupported
20-
from git.compat import xrange
21+
22+
import os.path as osp
2123

2224

2325
__all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_git_dir', 'name_to_object', 'short_to_long', 'deref_tag',
@@ -42,7 +44,7 @@ def is_git_dir(d):
4244
if isdir(join(d, 'objects')) and isdir(join(d, 'refs')):
4345
headref = join(d, 'HEAD')
4446
return isfile(headref) or \
45-
(os.path.islink(headref) and
47+
(osp.islink(headref) and
4648
os.readlink(headref).startswith('refs'))
4749
elif isfile(join(d, 'gitdir')) and isfile(join(d, 'commondir')) and isfile(join(d, 'gitfile')):
4850
raise WorkTreeRepositoryUnsupported(d)
@@ -62,7 +64,7 @@ def find_git_dir(d):
6264
else:
6365
if content.startswith('gitdir: '):
6466
path = content[8:]
65-
if not os.path.isabs(path):
67+
if not osp.isabs(path):
6668
path = join(dirname(d), path)
6769
return find_git_dir(path)
6870
# end handle exception

‎git/test/performance/lib.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
"""Contains library functions"""
2+
import logging
23
import os
3-
from git.test.lib import (
4-
TestBase
5-
)
64
import tempfile
7-
import logging
85

6+
from git import (
7+
Repo
8+
)
99
from git.db import (
1010
GitCmdObjectDB,
1111
GitDB
1212
)
13-
14-
from git import (
15-
Repo
13+
from git.test.lib import (
14+
TestBase
1615
)
1716
from git.util import rmtree
1817

18+
import os.path as osp
19+
20+
1921
#{ Invvariants
2022
k_env_git_repo = "GIT_PYTHON_TEST_GIT_REPO_BASE"
2123

@@ -52,7 +54,7 @@ def setUp(self):
5254
logging.info(
5355
("You can set the %s environment variable to a .git repository of" % k_env_git_repo) +
5456
"your choice - defaulting to the gitpython repository")
55-
repo_path = os.path.dirname(__file__)
57+
repo_path = osp.dirname(__file__)
5658
# end set some repo path
5759
self.gitrorepo = Repo(repo_path, odbt=GitCmdObjectDB, search_parent_directories=True)
5860
self.puregitrorepo = Repo(repo_path, odbt=GitDB, search_parent_directories=True)

‎git/test/performance/test_streams.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
"""Performance data streaming performance"""
22
from __future__ import print_function
33

4-
from time import time
54
import os
6-
import sys
75
import subprocess
6+
import sys
7+
from time import time
88

99
from git.test.lib import (
1010
with_rw_repo
1111
)
12-
from gitdb.util import bin_to_hex
12+
from gitdb import (
13+
LooseObjectDB,
14+
IStream
15+
)
1316
from gitdb.test.lib import make_memory_file
17+
from gitdb.util import bin_to_hex
18+
19+
import os.path as osp
1420

1521
from .lib import (
1622
TestBigRepoR
1723
)
1824

19-
from gitdb import (
20-
LooseObjectDB,
21-
IStream
22-
)
23-
2425

2526
class TestObjDBPerformance(TestBigRepoR):
2627

@@ -31,7 +32,7 @@ class TestObjDBPerformance(TestBigRepoR):
3132
def test_large_data_streaming(self, rwrepo):
3233
# TODO: This part overlaps with the same file in gitdb.test.performance.test_stream
3334
# It should be shared if possible
34-
ldb = LooseObjectDB(os.path.join(rwrepo.git_dir, 'objects'))
35+
ldb = LooseObjectDB(osp.join(rwrepo.git_dir, 'objects'))
3536

3637
for randomize in range(2):
3738
desc = (randomize and 'random ') or ''
@@ -47,7 +48,7 @@ def test_large_data_streaming(self, rwrepo):
4748
elapsed_add = time() - st
4849
assert ldb.has_object(binsha)
4950
db_file = ldb.readable_db_object_path(bin_to_hex(binsha))
50-
fsize_kib = os.path.getsize(db_file) / 1000
51+
fsize_kib = osp.getsize(db_file) / 1000
5152

5253
size_kib = size / 1000
5354
msg = "Added %i KiB (filesize = %i KiB) of %s data to loose odb in %f s ( %f Write KiB / s)"
@@ -109,7 +110,7 @@ def test_large_data_streaming(self, rwrepo):
109110
assert gitsha == bin_to_hex(binsha) # we do it the same way, right ?
110111

111112
# as its the same sha, we reuse our path
112-
fsize_kib = os.path.getsize(db_file) / 1000
113+
fsize_kib = osp.getsize(db_file) / 1000
113114
msg = "Added %i KiB (filesize = %i KiB) of %s data to using git-hash-object in %f s ( %f Write KiB / s)"
114115
msg %= (size_kib, fsize_kib, desc, gelapsed_add, size_kib / gelapsed_add)
115116
print(msg, file=sys.stderr)

‎git/test/test_base.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,24 @@
99
import tempfile
1010
from unittest import skipIf
1111

12-
import git.objects.base as base
13-
from git.test.lib import (
14-
TestBase,
15-
assert_raises,
16-
with_rw_repo,
17-
with_rw_and_rw_remote_repo
18-
)
1912
from git import (
2013
Blob,
2114
Tree,
2215
Commit,
2316
TagObject
2417
)
18+
from git.compat import is_win
2519
from git.objects.util import get_object_type_by_name
20+
from git.test.lib import (
21+
TestBase,
22+
assert_raises,
23+
with_rw_repo,
24+
with_rw_and_rw_remote_repo
25+
)
2626
from gitdb.util import hex_to_bin
27-
from git.compat import is_win
27+
28+
import git.objects.base as base
29+
import os.path as osp
2830

2931

3032
class TestBase(TestBase):
@@ -103,27 +105,27 @@ def test_object_resolution(self):
103105
@with_rw_repo('HEAD', bare=True)
104106
def test_with_bare_rw_repo(self, bare_rw_repo):
105107
assert bare_rw_repo.config_reader("repository").getboolean("core", "bare")
106-
assert os.path.isfile(os.path.join(bare_rw_repo.git_dir, 'HEAD'))
108+
assert osp.isfile(osp.join(bare_rw_repo.git_dir, 'HEAD'))
107109

108110
@with_rw_repo('0.1.6')
109111
def test_with_rw_repo(self, rw_repo):
110112
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
111-
assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
113+
assert osp.isdir(osp.join(rw_repo.working_tree_dir, 'lib'))
112114

113115
#@skipIf(HIDE_WINDOWS_FREEZE_ERRORS, "FIXME: Freezes! sometimes...")
114116
@with_rw_and_rw_remote_repo('0.1.6')
115117
def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo):
116118
assert not rw_repo.config_reader("repository").getboolean("core", "bare")
117119
assert rw_remote_repo.config_reader("repository").getboolean("core", "bare")
118-
assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib'))
120+
assert osp.isdir(osp.join(rw_repo.working_tree_dir, 'lib'))
119121

120122
@skipIf(sys.version_info < (3,) and is_win,
121123
"Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519")
122124
@with_rw_repo('0.1.6')
123125
def test_add_unicode(self, rw_repo):
124126
filename = u"שלום.txt"
125127

126-
file_path = os.path.join(rw_repo.working_dir, filename)
128+
file_path = osp.join(rw_repo.working_dir, filename)
127129

128130
# verify first that we could encode file name in this environment
129131
try:

‎git/test/test_commit.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,36 @@
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
from __future__ import print_function
88

9-
from git.test.lib import (
10-
TestBase,
11-
assert_equal,
12-
assert_not_equal,
13-
with_rw_repo,
14-
fixture_path,
15-
StringProcessAdapter
16-
)
9+
from datetime import datetime
10+
from io import BytesIO
11+
import re
12+
import sys
13+
import time
14+
1715
from git import (
1816
Commit,
1917
Actor,
2018
)
21-
from gitdb import IStream
22-
from git.test.lib import with_rw_directory
19+
from git import Repo
2320
from git.compat import (
2421
string_types,
2522
text_type
2623
)
27-
from git import Repo
24+
from git.objects.util import tzoffset, utc
2825
from git.repo.fun import touch
26+
from git.test.lib import (
27+
TestBase,
28+
assert_equal,
29+
assert_not_equal,
30+
with_rw_repo,
31+
fixture_path,
32+
StringProcessAdapter
33+
)
34+
from git.test.lib import with_rw_directory
35+
from gitdb import IStream
36+
37+
import os.path as osp
2938

30-
from io import BytesIO
31-
import time
32-
import sys
33-
import re
34-
import os
35-
from datetime import datetime
36-
from git.objects.util import tzoffset, utc
3739

3840
try:
3941
from unittest.mock import Mock
@@ -232,8 +234,8 @@ def test_rev_list_bisect_all(self):
232234

233235
@with_rw_directory
234236
def test_ambiguous_arg_iteration(self, rw_dir):
235-
rw_repo = Repo.init(os.path.join(rw_dir, 'test_ambiguous_arg'))
236-
path = os.path.join(rw_repo.working_tree_dir, 'master')
237+
rw_repo = Repo.init(osp.join(rw_dir, 'test_ambiguous_arg'))
238+
path = osp.join(rw_repo.working_tree_dir, 'master')
237239
touch(path)
238240
rw_repo.index.add([path])
239241
rw_repo.index.commit('initial commit')

‎git/test/test_config.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import glob
88
import io
9-
import os
109

1110
from git import (
1211
GitConfigParser
@@ -91,7 +90,7 @@ def test_read_write(self):
9190

9291
@with_rw_directory
9392
def test_lock_reentry(self, rw_dir):
94-
fpl = os.path.join(rw_dir, 'l')
93+
fpl = osp.join(rw_dir, 'l')
9594
gcp = GitConfigParser(fpl, read_only=False)
9695
with gcp as cw:
9796
cw.set_value('include', 'some_value', 'a')
@@ -103,7 +102,7 @@ def test_lock_reentry(self, rw_dir):
103102
GitConfigParser(fpl, read_only=False)
104103
# but work when the lock is removed
105104
with GitConfigParser(fpl, read_only=False):
106-
assert os.path.exists(fpl)
105+
assert osp.exists(fpl)
107106
# reentering with an existing lock must fail due to exclusive access
108107
with self.assertRaises(IOError):
109108
gcp.__enter__()
@@ -178,17 +177,17 @@ def check_test_value(cr, value):
178177
# end
179178

180179
# PREPARE CONFIG FILE A
181-
fpa = os.path.join(rw_dir, 'a')
180+
fpa = osp.join(rw_dir, 'a')
182181
with GitConfigParser(fpa, read_only=False) as cw:
183182
write_test_value(cw, 'a')
184183

185-
fpb = os.path.join(rw_dir, 'b')
186-
fpc = os.path.join(rw_dir, 'c')
184+
fpb = osp.join(rw_dir, 'b')
185+
fpc = osp.join(rw_dir, 'c')
187186
cw.set_value('include', 'relative_path_b', 'b')
188187
cw.set_value('include', 'doesntexist', 'foobar')
189188
cw.set_value('include', 'relative_cycle_a_a', 'a')
190189
cw.set_value('include', 'absolute_cycle_a_a', fpa)
191-
assert os.path.exists(fpa)
190+
assert osp.exists(fpa)
192191

193192
# PREPARE CONFIG FILE B
194193
with GitConfigParser(fpb, read_only=False) as cw:

‎git/test/test_db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
#
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6-
from git.test.lib import TestBase
76
from git.db import GitCmdObjectDB
8-
from gitdb.util import bin_to_hex
97
from git.exc import BadObject
10-
import os
8+
from git.test.lib import TestBase
9+
from gitdb.util import bin_to_hex
10+
11+
import os.path as osp
1112

1213

1314
class TestDB(TestBase):
1415

1516
def test_base(self):
16-
gdb = GitCmdObjectDB(os.path.join(self.rorepo.git_dir, 'objects'), self.rorepo.git)
17+
gdb = GitCmdObjectDB(osp.join(self.rorepo.git_dir, 'objects'), self.rorepo.git)
1718

1819
# partial to complete - works with everything
1920
hexsha = bin_to_hex(gdb.partial_to_complete_sha_hex("0.1.6"))

‎git/test/test_diff.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
7-
import os
8-
7+
import ddt
8+
from git import (
9+
Repo,
10+
GitCommandError,
11+
Diff,
12+
DiffIndex,
13+
NULL_TREE,
14+
)
15+
from git.cmd import Git
916
from git.test.lib import (
1017
TestBase,
1118
StringProcessAdapter,
@@ -14,18 +21,9 @@
1421
assert_true,
1522

1623
)
17-
1824
from git.test.lib import with_rw_directory
1925

20-
from git import (
21-
Repo,
22-
GitCommandError,
23-
Diff,
24-
DiffIndex,
25-
NULL_TREE,
26-
)
27-
import ddt
28-
from git.cmd import Git
26+
import os.path as osp
2927

3028

3129
@ddt.ddt
@@ -54,7 +52,7 @@ def _assert_diff_format(self, diffs):
5452
def test_diff_with_staged_file(self, rw_dir):
5553
# SETUP INDEX WITH MULTIPLE STAGES
5654
r = Repo.init(rw_dir)
57-
fp = os.path.join(rw_dir, 'hello.txt')
55+
fp = osp.join(rw_dir, 'hello.txt')
5856
with open(fp, 'w') as fs:
5957
fs.write("hello world")
6058
r.git.add(Git.polish_url(fp))

‎git/test/test_docs.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from git.test.lib import TestBase
1010
from git.test.lib.helper import with_rw_directory
1111

12+
import os.path as osp
13+
1214

1315
class Tutorials(TestBase):
1416

@@ -23,7 +25,7 @@ def tearDown(self):
2325
def test_init_repo_object(self, rw_dir):
2426
# [1-test_init_repo_object]
2527
from git import Repo
26-
join = os.path.join
28+
join = osp.join
2729

2830
# rorepo is a Repo instance pointing to the git-python repository.
2931
# For all you know, the first argument to Repo is a path to the repository
@@ -62,7 +64,7 @@ def test_init_repo_object(self, rw_dir):
6264

6365
# repository paths
6466
# [7-test_init_repo_object]
65-
assert os.path.isdir(cloned_repo.working_tree_dir) # directory with your work files
67+
assert osp.isdir(cloned_repo.working_tree_dir) # directory with your work files
6668
assert cloned_repo.git_dir.startswith(cloned_repo.working_tree_dir) # directory containing the git repository
6769
assert bare_repo.working_tree_dir is None # bare repositories have no working tree
6870
# ![7-test_init_repo_object]
@@ -146,7 +148,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
146148
self.assertEqual(new_branch.checkout(), cloned_repo.active_branch) # checking out branch adjusts the wtree
147149
self.assertEqual(new_branch.commit, past.commit) # Now the past is checked out
148150

149-
new_file_path = os.path.join(cloned_repo.working_tree_dir, 'my-new-file')
151+
new_file_path = osp.join(cloned_repo.working_tree_dir, 'my-new-file')
150152
open(new_file_path, 'wb').close() # create new file in working tree
151153
cloned_repo.index.add([new_file_path]) # add it to the index
152154
# Commit the changes to deviate masters history
@@ -162,7 +164,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
162164
# now new_branch is ahead of master, which probably should be checked out and reset softly.
163165
# note that all these operations didn't touch the working tree, as we managed it ourselves.
164166
# This definitely requires you to know what you are doing :) !
165-
assert os.path.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
167+
assert osp.basename(new_file_path) in new_branch.commit.tree # new file is now in tree
166168
master.commit = new_branch.commit # let master point to most recent commit
167169
cloned_repo.head.reference = master # we adjusted just the reference, not the working tree or index
168170
# ![13-test_init_repo_object]
@@ -192,7 +194,7 @@ def update(self, op_code, cur_count, max_count=None, message=''):
192194
def test_references_and_objects(self, rw_dir):
193195
# [1-test_references_and_objects]
194196
import git
195-
repo = git.Repo.clone_from(self._small_repo_url(), os.path.join(rw_dir, 'repo'), branch='master')
197+
repo = git.Repo.clone_from(self._small_repo_url(), osp.join(rw_dir, 'repo'), branch='master')
196198

197199
heads = repo.heads
198200
master = heads.master # lists can be accessed by name for convenience
@@ -264,7 +266,7 @@ def test_references_and_objects(self, rw_dir):
264266

265267
# [11-test_references_and_objects]
266268
hct.blobs[0].data_stream.read() # stream object to read data from
267-
hct.blobs[0].stream_data(open(os.path.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream
269+
hct.blobs[0].stream_data(open(osp.join(rw_dir, 'blob_data'), 'wb')) # write data to given stream
268270
# ![11-test_references_and_objects]
269271

270272
# [12-test_references_and_objects]
@@ -350,11 +352,11 @@ def test_references_and_objects(self, rw_dir):
350352
# Access blob objects
351353
for (path, stage), entry in index.entries.items(): # @UnusedVariable
352354
pass
353-
new_file_path = os.path.join(repo.working_tree_dir, 'new-file-name')
355+
new_file_path = osp.join(repo.working_tree_dir, 'new-file-name')
354356
open(new_file_path, 'w').close()
355357
index.add([new_file_path]) # add a new file to the index
356358
index.remove(['LICENSE']) # remove an existing one
357-
assert os.path.isfile(os.path.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched
359+
assert osp.isfile(osp.join(repo.working_tree_dir, 'LICENSE')) # working tree is untouched
358360

359361
self.assertEqual(index.commit("my commit message").type, 'commit') # commit changed index
360362
repo.active_branch.commit = repo.commit('HEAD~1') # forget last commit
@@ -373,11 +375,11 @@ def test_references_and_objects(self, rw_dir):
373375
# merge two trees three-way into memory
374376
merge_index = IndexFile.from_tree(repo, 'HEAD~10', 'HEAD', repo.merge_base('HEAD~10', 'HEAD'))
375377
# and persist it
376-
merge_index.write(os.path.join(rw_dir, 'merged_index'))
378+
merge_index.write(osp.join(rw_dir, 'merged_index'))
377379
# ![24-test_references_and_objects]
378380

379381
# [25-test_references_and_objects]
380-
empty_repo = git.Repo.init(os.path.join(rw_dir, 'empty'))
382+
empty_repo = git.Repo.init(osp.join(rw_dir, 'empty'))
381383
origin = empty_repo.create_remote('origin', repo.remotes.origin.url)
382384
assert origin.exists()
383385
assert origin == empty_repo.remotes.origin == empty_repo.remotes['origin']
@@ -480,8 +482,8 @@ def test_submodules(self):
480482
def test_add_file_and_commit(self, rw_dir):
481483
import git
482484

483-
repo_dir = os.path.join(rw_dir, 'my-new-repo')
484-
file_name = os.path.join(repo_dir, 'new-file')
485+
repo_dir = osp.join(rw_dir, 'my-new-repo')
486+
file_name = osp.join(repo_dir, 'new-file')
485487

486488
r = git.Repo.init(repo_dir)
487489
# This function just creates an empty file ...

‎git/test/test_git.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
import os
8-
import sys
98
import subprocess
9+
import sys
1010

11+
from git import (
12+
Git,
13+
GitCommandError,
14+
GitCommandNotFound,
15+
Repo,
16+
cmd
17+
)
18+
from git.compat import PY3, is_darwin
1119
from git.test.lib import (
1220
TestBase,
1321
patch,
@@ -17,18 +25,12 @@
1725
assert_match,
1826
fixture_path
1927
)
20-
from git import (
21-
Git,
22-
GitCommandError,
23-
GitCommandNotFound,
24-
Repo,
25-
cmd
26-
)
2728
from git.test.lib import with_rw_directory
28-
29-
from git.compat import PY3, is_darwin
3029
from git.util import finalize_process
3130

31+
import os.path as osp
32+
33+
3234
try:
3335
from unittest import mock
3436
except ImportError:
@@ -147,7 +149,7 @@ def test_cmd_override(self):
147149
exc = GitCommandNotFound
148150
try:
149151
# set it to something that doens't exist, assure it raises
150-
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = os.path.join(
152+
type(self.git).GIT_PYTHON_GIT_EXECUTABLE = osp.join(
151153
"some", "path", "which", "doesn't", "exist", "gitbinary")
152154
self.failUnlessRaises(exc, self.git.version)
153155
finally:
@@ -198,13 +200,13 @@ def test_environment(self, rw_dir):
198200
self.assertEqual(new_env, {'VARKEY': 'VARVALUE'})
199201
self.assertEqual(self.git.environment(), {})
200202

201-
path = os.path.join(rw_dir, 'failing-script.sh')
203+
path = osp.join(rw_dir, 'failing-script.sh')
202204
with open(path, 'wt') as stream:
203205
stream.write("#!/usr/bin/env sh\n"
204206
"echo FOO\n")
205207
os.chmod(path, 0o777)
206208

207-
rw_repo = Repo.init(os.path.join(rw_dir, 'repo'))
209+
rw_repo = Repo.init(osp.join(rw_dir, 'repo'))
208210
remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo")
209211

210212
with rw_repo.git.custom_environment(GIT_SSH=path):

‎git/test/test_index.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@
4343
fixture,
4444
with_rw_repo
4545
)
46-
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
4746
from git.test.lib import with_rw_directory
4847
from git.util import Actor, rmtree
48+
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
4949
from gitdb.base import IStream
5050
from gitdb.util import hex_to_bin
5151

52+
import os.path as osp
53+
5254

5355
class TestIndex(TestBase):
5456

@@ -85,7 +87,7 @@ def _reset_progress(self):
8587
def _assert_entries(self, entries):
8688
for entry in entries:
8789
assert isinstance(entry, BaseIndexEntry)
88-
assert not os.path.isabs(entry.path)
90+
assert not osp.isabs(entry.path)
8991
assert "\\" not in entry.path
9092
# END for each entry
9193

@@ -329,7 +331,7 @@ def test_index_file_diffing(self, rw_repo):
329331

330332
# reset the working copy as well to current head,to pull 'back' as well
331333
new_data = b"will be reverted"
332-
file_path = os.path.join(rw_repo.working_tree_dir, "CHANGES")
334+
file_path = osp.join(rw_repo.working_tree_dir, "CHANGES")
333335
with open(file_path, "wb") as fp:
334336
fp.write(new_data)
335337
index.reset(rev_head_parent, working_tree=True)
@@ -340,26 +342,26 @@ def test_index_file_diffing(self, rw_repo):
340342
assert fp.read() != new_data
341343

342344
# test full checkout
343-
test_file = os.path.join(rw_repo.working_tree_dir, "CHANGES")
345+
test_file = osp.join(rw_repo.working_tree_dir, "CHANGES")
344346
with open(test_file, 'ab') as fd:
345347
fd.write(b"some data")
346348
rval = index.checkout(None, force=True, fprogress=self._fprogress)
347349
assert 'CHANGES' in list(rval)
348350
self._assert_fprogress([None])
349-
assert os.path.isfile(test_file)
351+
assert osp.isfile(test_file)
350352

351353
os.remove(test_file)
352354
rval = index.checkout(None, force=False, fprogress=self._fprogress)
353355
assert 'CHANGES' in list(rval)
354356
self._assert_fprogress([None])
355-
assert os.path.isfile(test_file)
357+
assert osp.isfile(test_file)
356358

357359
# individual file
358360
os.remove(test_file)
359361
rval = index.checkout(test_file, fprogress=self._fprogress)
360362
self.assertEqual(list(rval)[0], 'CHANGES')
361363
self._assert_fprogress([test_file])
362-
assert os.path.exists(test_file)
364+
assert osp.exists(test_file)
363365

364366
# checking out non-existing file throws
365367
self.failUnlessRaises(CheckoutError, index.checkout, "doesnt_exist_ever.txt.that")
@@ -373,7 +375,7 @@ def test_index_file_diffing(self, rw_repo):
373375
index.checkout(test_file)
374376
except CheckoutError as e:
375377
self.assertEqual(len(e.failed_files), 1)
376-
self.assertEqual(e.failed_files[0], os.path.basename(test_file))
378+
self.assertEqual(e.failed_files[0], osp.basename(test_file))
377379
self.assertEqual(len(e.failed_files), len(e.failed_reasons))
378380
self.assertIsInstance(e.failed_reasons[0], string_types)
379381
self.assertEqual(len(e.valid_files), 0)
@@ -388,7 +390,7 @@ def test_index_file_diffing(self, rw_repo):
388390
assert not open(test_file, 'rb').read().endswith(append_data)
389391

390392
# checkout directory
391-
rmtree(os.path.join(rw_repo.working_tree_dir, "lib"))
393+
rmtree(osp.join(rw_repo.working_tree_dir, "lib"))
392394
rval = index.checkout('lib')
393395
assert len(list(rval)) > 1
394396

@@ -399,7 +401,7 @@ def _count_existing(self, repo, files):
399401
existing = 0
400402
basedir = repo.working_tree_dir
401403
for f in files:
402-
existing += os.path.isfile(os.path.join(basedir, f))
404+
existing += osp.isfile(osp.join(basedir, f))
403405
# END for each deleted file
404406
return existing
405407
# END num existing helper
@@ -458,7 +460,7 @@ def mixed_iterator():
458460
self.failUnlessRaises(TypeError, index.remove, [1])
459461

460462
# absolute path
461-
deleted_files = index.remove([os.path.join(rw_repo.working_tree_dir, "lib")], r=True)
463+
deleted_files = index.remove([osp.join(rw_repo.working_tree_dir, "lib")], r=True)
462464
assert len(deleted_files) > 1
463465
self.failUnlessRaises(ValueError, index.remove, ["/doesnt/exists"])
464466

@@ -525,9 +527,9 @@ def mixed_iterator():
525527
# re-add all files in lib
526528
# get the lib folder back on disk, but get an index without it
527529
index.reset(new_commit.parents[0], working_tree=True).reset(new_commit, working_tree=False)
528-
lib_file_path = os.path.join("lib", "git", "__init__.py")
530+
lib_file_path = osp.join("lib", "git", "__init__.py")
529531
assert (lib_file_path, 0) not in index.entries
530-
assert os.path.isfile(os.path.join(rw_repo.working_tree_dir, lib_file_path))
532+
assert osp.isfile(osp.join(rw_repo.working_tree_dir, lib_file_path))
531533

532534
# directory
533535
entries = index.add(['lib'], fprogress=self._fprogress_add)
@@ -536,14 +538,14 @@ def mixed_iterator():
536538
assert len(entries) > 1
537539

538540
# glob
539-
entries = index.reset(new_commit).add([os.path.join('lib', 'git', '*.py')], fprogress=self._fprogress_add)
541+
entries = index.reset(new_commit).add([osp.join('lib', 'git', '*.py')], fprogress=self._fprogress_add)
540542
self._assert_entries(entries)
541543
self._assert_fprogress(entries)
542544
self.assertEqual(len(entries), 14)
543545

544546
# same file
545547
entries = index.reset(new_commit).add(
546-
[os.path.join(rw_repo.working_tree_dir, 'lib', 'git', 'head.py')] * 2, fprogress=self._fprogress_add)
548+
[osp.join(rw_repo.working_tree_dir, 'lib', 'git', 'head.py')] * 2, fprogress=self._fprogress_add)
547549
self._assert_entries(entries)
548550
self.assertEqual(entries[0].mode & 0o644, 0o644)
549551
# would fail, test is too primitive to handle this case
@@ -583,7 +585,7 @@ def mixed_iterator():
583585
for target in ('/etc/nonexisting', '/etc/passwd', '/etc'):
584586
basename = "my_real_symlink"
585587

586-
link_file = os.path.join(rw_repo.working_tree_dir, basename)
588+
link_file = osp.join(rw_repo.working_tree_dir, basename)
587589
os.symlink(target, link_file)
588590
entries = index.reset(new_commit).add([link_file], fprogress=self._fprogress_add)
589591
self._assert_entries(entries)
@@ -645,7 +647,7 @@ def mixed_iterator():
645647
# TEST RENAMING
646648
def assert_mv_rval(rval):
647649
for source, dest in rval:
648-
assert not os.path.exists(source) and os.path.exists(dest)
650+
assert not osp.exists(source) and osp.exists(dest)
649651
# END for each renamed item
650652
# END move assertion utility
651653

@@ -661,7 +663,7 @@ def assert_mv_rval(rval):
661663
paths = ['LICENSE', 'VERSION', 'doc']
662664
rval = index.move(paths, dry_run=True)
663665
self.assertEqual(len(rval), 2)
664-
assert os.path.exists(paths[0])
666+
assert osp.exists(paths[0])
665667

666668
# again, no dry run
667669
rval = index.move(paths)
@@ -719,8 +721,8 @@ def make_paths():
719721
index.add(files, write=True)
720722
if is_win:
721723
hp = hook_path('pre-commit', index.repo.git_dir)
722-
hpd = os.path.dirname(hp)
723-
if not os.path.isdir(hpd):
724+
hpd = osp.dirname(hp)
725+
if not osp.isdir(hpd):
724726
os.mkdir(hpd)
725727
with open(hp, "wt") as fp:
726728
fp.write("#!/usr/bin/env sh\necho stdout; echo stderr 1>&2; exit 1")
@@ -766,7 +768,7 @@ def make_paths():
766768
for fkey in keys:
767769
assert fkey in index.entries
768770
for absfile in absfiles:
769-
assert os.path.isfile(absfile)
771+
assert osp.isfile(absfile)
770772

771773
@with_rw_repo('HEAD')
772774
def test_compare_write_tree(self, rw_repo):
@@ -815,7 +817,7 @@ def test_index_bare_add(self, rw_bare_repo):
815817

816818
# Adding using a path should still require a non-bare repository.
817819
asserted = False
818-
path = os.path.join('git', 'test', 'test_index.py')
820+
path = osp.join('git', 'test', 'test_index.py')
819821
try:
820822
rw_bare_repo.index.add([path])
821823
except InvalidGitRepositoryError:
@@ -829,7 +831,7 @@ def test_index_bare_add(self, rw_bare_repo):
829831
@with_rw_directory
830832
def test_add_utf8P_path(self, rw_dir):
831833
# NOTE: fp is not a Unicode object in python 2 (which is the source of the problem)
832-
fp = os.path.join(rw_dir, 'ø.txt')
834+
fp = osp.join(rw_dir, 'ø.txt')
833835
with open(fp, 'wb') as fs:
834836
fs.write(u'content of ø'.encode('utf-8'))
835837

@@ -840,7 +842,7 @@ def test_add_utf8P_path(self, rw_dir):
840842
@with_rw_directory
841843
def test_add_a_file_with_wildcard_chars(self, rw_dir):
842844
# see issue #407
843-
fp = os.path.join(rw_dir, '[.exe')
845+
fp = osp.join(rw_dir, '[.exe')
844846
with open(fp, "wb") as f:
845847
f.write(b'something')
846848

‎git/test/test_reflog.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
from git.test.lib import (
2-
TestBase,
3-
fixture_path
4-
)
1+
import os
2+
import tempfile
3+
54
from git.objects import IndexObject
65
from git.refs import (
76
RefLogEntry,
87
RefLog
98
)
9+
from git.test.lib import (
10+
TestBase,
11+
fixture_path
12+
)
1013
from git.util import Actor, rmtree
1114
from gitdb.util import hex_to_bin
1215

13-
import tempfile
14-
import os
16+
import os.path as osp
1517

1618

1719
class TestRefLog(TestBase):
@@ -42,7 +44,7 @@ def test_base(self):
4244
os.mkdir(tdir)
4345

4446
rlp_master_ro = RefLog.path(self.rorepo.head)
45-
assert os.path.isfile(rlp_master_ro)
47+
assert osp.isfile(rlp_master_ro)
4648

4749
# simple read
4850
reflog = RefLog.from_file(rlp_master_ro)
@@ -70,7 +72,7 @@ def test_base(self):
7072
cr = self.rorepo.config_reader()
7173
for rlp in (rlp_head, rlp_master):
7274
reflog = RefLog.from_file(rlp)
73-
tfile = os.path.join(tdir, os.path.basename(rlp))
75+
tfile = osp.join(tdir, osp.basename(rlp))
7476
reflog.to_file(tfile)
7577
assert reflog.write() is reflog
7678

‎git/test/test_refs.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
from git.test.lib import (
8-
TestBase,
9-
with_rw_repo
10-
)
7+
from itertools import chain
8+
119
from git import (
1210
Reference,
1311
Head,
@@ -18,11 +16,15 @@
1816
GitCommandError,
1917
RefLog
2018
)
21-
import git.refs as refs
22-
from git.util import Actor
2319
from git.objects.tag import TagObject
24-
from itertools import chain
25-
import os
20+
from git.test.lib import (
21+
TestBase,
22+
with_rw_repo
23+
)
24+
from git.util import Actor
25+
26+
import git.refs as refs
27+
import os.path as osp
2628

2729

2830
class TestRefs(TestBase):
@@ -268,10 +270,10 @@ def test_head_reset(self, rw_repo):
268270
assert tmp_head == new_head and tmp_head.object == new_head.object
269271

270272
logfile = RefLog.path(tmp_head)
271-
assert os.path.isfile(logfile)
273+
assert osp.isfile(logfile)
272274
Head.delete(rw_repo, tmp_head)
273275
# deletion removes the log as well
274-
assert not os.path.isfile(logfile)
276+
assert not osp.isfile(logfile)
275277
heads = rw_repo.heads
276278
assert tmp_head not in heads and new_head not in heads
277279
# force on deletion testing would be missing here, code looks okay though ;)
@@ -450,12 +452,12 @@ def test_head_reset(self, rw_repo):
450452
symbol_ref_path = "refs/symbol_ref"
451453
symref = SymbolicReference(rw_repo, symbol_ref_path)
452454
assert symref.path == symbol_ref_path
453-
symbol_ref_abspath = os.path.join(rw_repo.git_dir, symref.path)
455+
symbol_ref_abspath = osp.join(rw_repo.git_dir, symref.path)
454456

455457
# set it
456458
symref.reference = new_head
457459
assert symref.reference == new_head
458-
assert os.path.isfile(symbol_ref_abspath)
460+
assert osp.isfile(symbol_ref_abspath)
459461
assert symref.commit == new_head.commit
460462

461463
for name in ('absname', 'folder/rela_name'):
@@ -507,7 +509,7 @@ def test_head_reset(self, rw_repo):
507509
rw_repo.head.reference = Head.create(rw_repo, "master")
508510

509511
# At least the head should still exist
510-
assert os.path.isfile(os.path.join(rw_repo.git_dir, 'HEAD'))
512+
assert osp.isfile(osp.join(rw_repo.git_dir, 'HEAD'))
511513
refs = list(SymbolicReference.iter_items(rw_repo))
512514
assert len(refs) == 1
513515

‎git/test/test_repo.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,16 +203,16 @@ def test_init(self):
203203
prev_cwd = os.getcwd()
204204
os.chdir(tempfile.gettempdir())
205205
git_dir_rela = "repos/foo/bar.git"
206-
del_dir_abs = os.path.abspath("repos")
207-
git_dir_abs = os.path.abspath(git_dir_rela)
206+
del_dir_abs = osp.abspath("repos")
207+
git_dir_abs = osp.abspath(git_dir_rela)
208208
try:
209209
# with specific path
210210
for path in (git_dir_rela, git_dir_abs):
211211
r = Repo.init(path=path, bare=True)
212212
self.assertIsInstance(r, Repo)
213213
assert r.bare is True
214214
assert not r.has_separate_working_tree()
215-
assert os.path.isdir(r.git_dir)
215+
assert osp.isdir(r.git_dir)
216216

217217
self._assert_empty_repo(r)
218218

@@ -306,16 +306,16 @@ def test_is_dirty(self):
306306
def test_is_dirty_with_path(self, rwrepo):
307307
assert rwrepo.is_dirty(path="git") is False
308308

309-
with open(os.path.join(rwrepo.working_dir, "git", "util.py"), "at") as f:
309+
with open(osp.join(rwrepo.working_dir, "git", "util.py"), "at") as f:
310310
f.write("junk")
311311
assert rwrepo.is_dirty(path="git") is True
312312
assert rwrepo.is_dirty(path="doc") is False
313313

314-
rwrepo.git.add(os.path.join("git", "util.py"))
314+
rwrepo.git.add(osp.join("git", "util.py"))
315315
assert rwrepo.is_dirty(index=False, path="git") is False
316316
assert rwrepo.is_dirty(path="git") is True
317317

318-
with open(os.path.join(rwrepo.working_dir, "doc", "no-such-file.txt"), "wt") as f:
318+
with open(osp.join(rwrepo.working_dir, "doc", "no-such-file.txt"), "wt") as f:
319319
f.write("junk")
320320
assert rwrepo.is_dirty(path="doc") is False
321321
assert rwrepo.is_dirty(untracked_files=True, path="doc") is True
@@ -494,10 +494,10 @@ def test_tilde_and_env_vars_in_repo_path(self, rw_dir):
494494
ph = os.environ.get('HOME')
495495
try:
496496
os.environ['HOME'] = rw_dir
497-
Repo.init(os.path.join('~', 'test.git'), bare=True)
497+
Repo.init(osp.join('~', 'test.git'), bare=True)
498498

499499
os.environ['FOO'] = rw_dir
500-
Repo.init(os.path.join('$FOO', 'test.git'), bare=True)
500+
Repo.init(osp.join('$FOO', 'test.git'), bare=True)
501501
finally:
502502
if ph:
503503
os.environ['HOME'] = ph
@@ -785,21 +785,21 @@ def test_submodule_update(self, rwrepo):
785785
@with_rw_repo('HEAD')
786786
def test_git_file(self, rwrepo):
787787
# Move the .git directory to another location and create the .git file.
788-
real_path_abs = os.path.abspath(join_path_native(rwrepo.working_tree_dir, '.real'))
788+
real_path_abs = osp.abspath(join_path_native(rwrepo.working_tree_dir, '.real'))
789789
os.rename(rwrepo.git_dir, real_path_abs)
790790
git_file_path = join_path_native(rwrepo.working_tree_dir, '.git')
791791
with open(git_file_path, 'wb') as fp:
792792
fp.write(fixture('git_file'))
793793

794794
# Create a repo and make sure it's pointing to the relocated .git directory.
795795
git_file_repo = Repo(rwrepo.working_tree_dir)
796-
self.assertEqual(os.path.abspath(git_file_repo.git_dir), real_path_abs)
796+
self.assertEqual(osp.abspath(git_file_repo.git_dir), real_path_abs)
797797

798798
# Test using an absolute gitdir path in the .git file.
799799
with open(git_file_path, 'wb') as fp:
800800
fp.write(('gitdir: %s\n' % real_path_abs).encode('ascii'))
801801
git_file_repo = Repo(rwrepo.working_tree_dir)
802-
self.assertEqual(os.path.abspath(git_file_repo.git_dir), real_path_abs)
802+
self.assertEqual(osp.abspath(git_file_repo.git_dir), real_path_abs)
803803

804804
@skipIf(HIDE_WINDOWS_KNOWN_ERRORS and PY3,
805805
"FIXME: smmp fails with: TypeError: Can't convert 'bytes' object to str implicitly")
@@ -840,7 +840,7 @@ def test_empty_repo(self, rw_dir):
840840
# It's expected to not be able to access a tree
841841
self.failUnlessRaises(ValueError, r.tree)
842842

843-
new_file_path = os.path.join(rw_dir, "new_file.ext")
843+
new_file_path = osp.join(rw_dir, "new_file.ext")
844844
touch(new_file_path)
845845
r.index.add([new_file_path])
846846
r.index.commit("initial commit\nBAD MESSAGE 1\n")

‎git/test/test_tree.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
from io import BytesIO
8-
import os
98
import sys
109
from unittest.case import skipIf
1110

1211
from git import (
1312
Tree,
1413
Blob
1514
)
16-
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
1715
from git.test.lib import TestBase
16+
from git.util import HIDE_WINDOWS_KNOWN_ERRORS
17+
18+
import os.path as osp
1819

1920

2021
class TestTree(TestBase):
@@ -90,12 +91,12 @@ def test_traverse(self):
9091
assert len(set(b for b in root if isinstance(b, Blob)) | set(root.blobs)) == len(root.blobs)
9192
subitem = trees[0][0]
9293
assert "/" in subitem.path
93-
assert subitem.name == os.path.basename(subitem.path)
94+
assert subitem.name == osp.basename(subitem.path)
9495

9596
# assure that at some point the traversed paths have a slash in them
9697
found_slash = False
9798
for item in root.traverse():
98-
assert os.path.isabs(item.abspath)
99+
assert osp.isabs(item.abspath)
99100
if '/' in item.path:
100101
found_slash = True
101102
# END check for slash

‎git/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def stream_copy(source, destination, chunk_size=512 * 1024):
128128

129129

130130
def join_path(a, *p):
131-
"""Join path tokens together similar to os.path.join, but always use
131+
"""Join path tokens together similar to osp.join, but always use
132132
'/' instead of possibly '\' on windows."""
133133
path = a
134134
for b in p:
@@ -206,7 +206,7 @@ def is_exec(fpath):
206206
progs = []
207207
if not path:
208208
path = os.environ["PATH"]
209-
for folder in path.split(osp.pathsep):
209+
for folder in path.split(os.pathsep):
210210
folder = folder.strip('"')
211211
if folder:
212212
exe_path = osp.join(folder, program)
@@ -222,7 +222,7 @@ def _cygexpath(drive, path):
222222
# It's an error, leave it alone just slashes)
223223
p = path
224224
else:
225-
p = path and osp.normpath(osp.expandvars(os.path.expanduser(path)))
225+
p = path and osp.normpath(osp.expandvars(osp.expanduser(path)))
226226
if osp.isabs(p):
227227
if drive:
228228
# Confusing, maybe a remote system should expand vars.

0 commit comments

Comments
 (0)
Please sign in to comment.