summaryrefslogtreecommitdiff
path: root/morphlib/plugins/branch_and_merge_plugin.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/plugins/branch_and_merge_plugin.py')
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index a65b28ed..0c6209da 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -195,8 +195,8 @@ class BranchAndMergePlugin(cliapp.Plugin):
def resolve_ref(self, repodir, ref):
try:
- return self.app.runcmd(['git', 'show-ref', ref],
- cwd=repodir).split()[0]
+ return self.app.runcmd(['git', 'rev-parse', '--verify', ref],
+ cwd=repodir)[0:40]
except:
return None
@@ -517,11 +517,15 @@ class BranchAndMergePlugin(cliapp.Plugin):
new_branch = args[1]
commit = 'master' if len(args) == 2 else args[2]
+ self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app)
+ if self.lrc.get_repo(repo).ref_exists(new_branch):
+ raise cliapp.AppException('branch %s already exists in '
+ 'repository %s' % (new_branch, repo))
+
# Create the system branch directory.
workspace = self.deduce_workspace()
branch_dir = os.path.join(workspace, new_branch)
os.makedirs(branch_dir)
- self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app)
try:
# Create a .morph-system-branch directory to clearly identify
@@ -541,11 +545,6 @@ class BranchAndMergePlugin(cliapp.Plugin):
repo_dir = os.path.join(branch_dir, self.convert_uri_to_path(repo))
self.clone_to_directory(repo_dir, repo, commit)
- # Check if branch already exists locally or in a remote
- if self.resolve_ref(repo_dir, new_branch) is not None:
- raise cliapp.AppException('branch %s already exists in '
- 'repository %s' % (new_branch, repo))
-
# Create a new branch in the local morphs repository.
self.app.runcmd(['git', 'checkout', '-b', new_branch, commit],
cwd=repo_dir)