diff --git a/project.py b/project.py index 48ab8475..06240b7e 100644 --- a/project.py +++ b/project.py @@ -748,16 +748,31 @@ class Project(object): def StartBranch(self, name): """Create a new branch off the manifest's revision. """ - branch = self.GetBranch(name) - branch.remote = self.GetRemote(self.remote.name) - branch.merge = self.revision + try: + self.bare_git.rev_parse(R_HEADS + name) + exists = True + except GitError: + exists = False; + + if exists: + if name == self.CurrentBranch: + return True + else: + cmd = ['checkout', name, '--'] + return GitCommand(self, cmd).Wait() == 0 - rev = branch.LocalMerge - cmd = ['checkout', '-b', branch.name, rev] - if GitCommand(self, cmd).Wait() == 0: - branch.Save() else: - raise GitError('%s checkout %s ' % (self.name, rev)) + branch = self.GetBranch(name) + branch.remote = self.GetRemote(self.remote.name) + branch.merge = self.revision + + rev = branch.LocalMerge + cmd = ['checkout', '-b', branch.name, rev] + if GitCommand(self, cmd).Wait() == 0: + branch.Save() + return True + else: + return False def CheckoutBranch(self, name): """Checkout a local topic branch. diff --git a/subcmds/init.py b/subcmds/init.py index d86c49ae..a32eaae0 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -131,7 +131,9 @@ default.xml will be used. m.Sync_LocalHalf() if is_new or m.CurrentBranch is None: - m.StartBranch('default') + if not m.StartBranch('default'): + print >>sys.stderr, 'fatal: cannot create default in manifest' + sys.exit(1) def _LinkManifest(self, name): if not name: diff --git a/subcmds/start.py b/subcmds/start.py index 4eb3e476..deced7c2 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -47,5 +47,13 @@ the configuration data is set up properly. print >>sys.stderr, "error: '%s' is not a valid name" % nb sys.exit(1) + err = [] for project in self.GetProjects(args[1:]): - project.StartBranch(nb) + if not project.StartBranch(nb): + err.append(project) + + if err: + err.sort() + for p in err: + print >>sys.stderr, "error: cannot start in %s" % p.relpath + sys.exit(1)