Skip to content

Commit f848c68

Browse files
committed
Merge pull request #4 from Oloshka/master
rerunning git.py init fix
2 parents 5375649 + 7d8d6da commit f848c68

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/repository.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ def create_repository(workspace):
5050
os.mkdir(workspace)
5151
os.chdir(workspace)
5252

53-
os.mkdir(GIT_DIR)
53+
if not os.path.exists(GIT_DIR):
54+
os.mkdir(GIT_DIR)
5455

55-
for new_dir in INIT_DIR:
56-
os.mkdir(new_dir)
56+
for new_dir in INIT_DIR:
57+
os.mkdir(new_dir)
5758

58-
for file_and_content in INIT_FILE:
59-
file_name = file_and_content[0]
60-
content = file_and_content[1]
61-
write_to_file(file_name, content)
59+
for file_and_content in INIT_FILE:
60+
file_name = file_and_content[0]
61+
content = file_and_content[1]
62+
write_to_file(file_name, content)
6263

6364

6465
init_config_dict = {

src/tests/test_init.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ def test_init_without_workspace(self):
3535
self._check_dirs_and_files(workspace)
3636
shutil.rmtree(GIT_DIR)
3737

38+
def test_init_in_existing_repository(self):
39+
workspace = "test"
40+
Command.cmd_init(workspace)
41+
os.chdir('..')
42+
try:
43+
Command.cmd_init(workspace)
44+
except OSError:
45+
self.assertEqual(1, 2, "Reinitialized existing repository failed")
46+
finally:
47+
os.chdir('..')
48+
shutil.rmtree(workspace)
49+
3850

3951
if __name__ == "__main__":
4052
unittest.main()

0 commit comments

Comments
 (0)