Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit 56c23a5

Browse files
committed
Add tests for repo_rename and fixed one logic bug in the rename code
1 parent b6673bc commit 56c23a5

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

sgit/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ def repo_rename(self, from_name, to_name):
165165
print(f'ERROR: from name and to name can\'t be the same value')
166166
return 1
167167

168-
if to_name not in current_repos:
168+
if to_name in current_repos:
169169
print(f'ERROR: Destination name already exists in config')
170-
return 1
170+
return 2
171171

172172
# Rename action
173173
config['repos'][to_name] = config['repos'][from_name]

tests/test_core.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,25 @@ def test_repo_set(sgit):
170170
config = sgit._get_config_file()
171171
assert config['repos']['1a']['clone-url'] == '2c'
172172
assert config['repos']['1a']['revision'] == '2d'
173+
174+
175+
def test_repo_rename(sgit):
176+
retcode = sgit.init_repo()
177+
assert retcode == None
178+
179+
## If source and destination repo name is the same, throw error
180+
retcode = sgit.repo_rename('foobar', 'foobar')
181+
assert retcode == 1
182+
183+
## If destination repo name already exists then throw error
184+
sgit.repo_add('qwerty', '[email protected]', 'master')
185+
retcode = sgit.repo_rename('foobar', 'qwerty')
186+
assert retcode == 2
187+
188+
sgit.repo_add('foobar', '[email protected]', 'master')
189+
retcode = sgit.repo_rename('foobar', 'barfoo')
190+
assert retcode is None
191+
192+
config = sgit._get_config_file()
193+
assert 'foobar' not in config['repos']
194+
assert 'barfoo' in config['repos']

0 commit comments

Comments
 (0)