Permalink
Browse files

Fix `git flow init`: crashed if master exists remote but not local.

  • Loading branch information...
1 parent 63924e3 commit 6d65350dbbef25070472ed994ac1f9cc9956786a @htgoebel committed Mar 9, 2012
Showing with 21 additions and 3 deletions.
  1. +4 −2 gitflow/bin/_init.py
  2. +17 −1 tests/gitflow/test_bin.py
View
@@ -16,7 +16,7 @@
# readline is optional and may not be available on all installations
pass
-from gitflow.core import GitFlow as CoreGitFlow, warn
+from gitflow.core import GitFlow as CoreGitFlow, warn, info
from gitflow.exceptions import (AlreadyInitialized, NotInitialized,
NoSuchLocalBranchError, NoSuchBranchError)
@@ -91,7 +91,9 @@ def _ask_branch(args, name, desc1, desc2, suggestions, filter=[]):
if not branch_name in local_branches:
remote_name = gitflow.origin_name(branch_name)
if remote_name in gitflow.branch_names(remote=True):
- gitflow.repo.branch(branch_name, remote_name)
+ branch = gitflow.repo.create_head(branch_name, remote_name)
+ info("Created local branch %s based on %s."
+ % (branch_name, remote_name))
else:
raise NoSuchLocalBranchError(branch_name)
View
@@ -215,6 +215,23 @@ def test_init_fails_if_develop_name_equals_master_name(self):
finally:
sys.stdin = _stdin
+
+ @remote_clone_from_fixture('sample_repo')
+ def test_init_with_master_existing_remote_but_not_local(self):
+ rsc0 = self.remote.branches['stable'].commit
+ text = '\n'.join(['my-remote', 'stable', 'devel',
+ 'feat/', 'rel/', 'hf/', 'sup/', 'ver'])
+ _stdin, sys.stdin = sys.stdin, StringIO(text)
+ try:
+ runGitFlow('init', '--force')
+ finally:
+ sys.stdin = _stdin
+ rsc1 = self.remote.branches['stable'].commit
+ lsc1 = self.repo.branches['stable'].commit
+ self.assertEqual(rsc0, rsc1)
+ self.assertEqual(rsc1, lsc1)
+
+
# These tests need a repo with only branches `foo` and `bar`
# or other names not selected for defaults
# :todo: give no master branch name (or white-spaces)
@@ -238,7 +255,6 @@ def assertNotInitialized(*args):
assertNotInitialized('rebase', 'recursion')
assertNotInitialized('pull', 'even')
-
class TestFeature(TestCase):
@copy_from_fixture('sample_repo')

0 comments on commit 6d65350

Please sign in to comment.