Skip to content

Commit

Permalink
Setup the git config user identity
Browse files Browse the repository at this point in the history
  • Loading branch information
turran committed Sep 26, 2024
1 parent bf2eb1c commit 11ca6b4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
19 changes: 18 additions & 1 deletion tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
class AddTestCase(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
# Setup git to have a proper user and email
gitconfig = git.config.get_config_path("global")
gc = git.GitConfigParser(gitconfig, read_only=False)

try:
name = gc.get_value("user", "name")
except:
name = None
if not name:
gc.set_value("user", "name", "test")
try:
email = gc.get_value("user", "email")
except:
email = None
if not email:
gc.set_value("user", "email", "[email protected]")
gc.release()

def cleanUp(self):
shutil.rmtree(self.tmpdir)
Expand Down Expand Up @@ -58,7 +75,7 @@ def test_add(self):
"origin",
"example1-feature1",
)
# Check the proper order of the commits, like git log --pretty=%s
repo = git.Repo(self.tmpdir)
# Check the proper order of the commits, like git log --pretty=%s
commits = [x.summary for x in repo.iter_commits("example1-final")]
self.assertEqual(commits, expected_commits)
20 changes: 19 additions & 1 deletion tests/test_remove.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import shutil
import tempfile
import unittest
Expand All @@ -11,6 +12,23 @@
class RemoveTestCase(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
# Setup git to have a proper user and email
gitconfig = git.config.get_config_path("global")
gc = git.GitConfigParser(gitconfig, read_only=False)

try:
name = gc.get_value("user", "name")
except:
name = None
if not name:
gc.set_value("user", "name", "test")
try:
email = gc.get_value("user", "email")
except:
email = None
if not email:
gc.set_value("user", "email", "[email protected]")
gc.release()

def cleanUp(self):
shutil.rmtree(self.tmpdir)
Expand Down Expand Up @@ -44,7 +62,7 @@ def test_remove(self):
expected_commits = ["Second commit", "Initial commit"]
guw = GUW(tomli.loads(config))
guw.remove(False, True, True, self.tmpdir, "example1-feature2")
# Check the proper order of the commits, like git log --pretty=%s
repo = git.Repo(self.tmpdir)
# Check the proper order of the commits, like git log --pretty=%s
commits = [x.summary for x in repo.iter_commits("example1-final")]
self.assertEqual(commits, expected_commits)

0 comments on commit 11ca6b4

Please sign in to comment.