summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/cmd.py8
-rw-r--r--lib/git/repo.py16
-rw-r--r--test/git/test_index.py12
-rw-r--r--test/git/test_repo.py7
4 files changed, 36 insertions, 7 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py
index 60912142..254b7dd3 100644
--- a/lib/git/cmd.py
+++ b/lib/git/cmd.py
@@ -63,8 +63,12 @@ class Git(object):
def __del__(self):
# did the process finish already so we have a return code ?
if self.proc.poll() is not None:
- return
-
+ return
+
+ # can be that nothing really exists anymore ...
+ if os is None:
+ return
+
# try to kill it
try:
os.kill(self.proc.pid, 2) # interrupt signal
diff --git a/lib/git/repo.py b/lib/git/repo.py
index 396dd129..f4caa3fb 100644
--- a/lib/git/repo.py
+++ b/lib/git/repo.py
@@ -131,6 +131,20 @@ class Repo(object):
self.working_dir = self._working_tree_dir or self.git_dir
self.git = Git(self.working_dir)
+ def __eq__(self, rhs):
+ if isinstance(rhs, Repo):
+ return self.git_dir == rhs.git_dir
+ return False
+
+ def __ne__(self, rhs):
+ return not self.__eq__(rhs)
+
+ def __hash__(self):
+ return hash(self.git_dir)
+
+ def __repr__(self):
+ return "%s(%r)" % (type(self).__name__, self.git_dir)
+
# Description property
def _get_description(self):
filename = os.path.join(self.git_dir, 'description')
@@ -145,6 +159,8 @@ class Repo(object):
del _get_description
del _set_description
+
+
@property
def working_tree_dir(self):
"""
diff --git a/test/git/test_index.py b/test/git/test_index.py
index 95f2b519..f0f5f115 100644
--- a/test/git/test_index.py
+++ b/test/git/test_index.py
@@ -147,6 +147,10 @@ class TestIndex(TestBase):
@with_rw_repo('0.1.6')
def test_index_merge_tree(self, rw_repo):
+ # A bit out of place, but we need a different repo for this:
+ assert self.rorepo != rw_repo and not (self.rorepo == rw_repo)
+ assert len(set((self.rorepo, self.rorepo, rw_repo, rw_repo))) == 2
+
# SINGLE TREE MERGE
# current index is at the (virtual) cur_commit
next_commit = "4c39f9da792792d4e73fc3a5effde66576ae128c"
@@ -546,10 +550,10 @@ class TestIndex(TestBase):
yield index.entries[index.get_entries_key('.gitignore', 0)]
for fid in range(3):
- fname = 'newfile%i' % fid
- open(fname, 'wb').write("abcd")
- yield Blob(rw_repo, Blob.NULL_HEX_SHA, 0100644, fname)
- # END for each new file
+ fname = 'newfile%i' % fid
+ open(fname, 'wb').write("abcd")
+ yield Blob(rw_repo, Blob.NULL_HEX_SHA, 0100644, fname)
+ # END for each new file
# END path producer
paths = list(make_paths())
index.add(paths, path_rewriter=rewriter)
diff --git a/test/git/test_repo.py b/test/git/test_repo.py
index 9a762bd9..ce79402a 100644
--- a/test/git/test_repo.py
+++ b/test/git/test_repo.py
@@ -115,7 +115,7 @@ class TestRepo(TestBase):
# we can add a file to the index ( if we are not bare )
if not repo.bare:
- pass
+ pass
# END test repos with working tree
@@ -327,3 +327,8 @@ class TestRepo(TestBase):
remote = self.rorepo.create_remote("new_remote", "git@server:repo.git")
self.rorepo.delete_remote(remote)
+
+ def test_comparison_and_hash(self):
+ # this is only a preliminary test, more testing done in test_index
+ assert self.rorepo == self.rorepo and not (self.rorepo != self.rorepo)
+ assert len(set((self.rorepo, self.rorepo))) == 1