This way we can store more branch config options in the future more
conveniently without having store them all in separate files or writing
our own code to parse the options into a branch config object or
something like that.
---
morphlib/plugins/branch_and_merge_plugin.py | 24 +++++++++++++---------
...reates-new-system-branch-not-from-master.stdout | 2 +-
.../branch-creates-new-system-branch.stdout | 2 +-
tests.branching/branch-works-anywhere.stdout | 20 +++++++++---------
tests.branching/checkout-existing-branch.stdout | 2 +-
tests.branching/checkout-non-aliased-repos.stdout | 4 ++--
tests.branching/checkout-works-anywhere.stdout | 6 +++---
7 files changed, 32 insertions(+), 28 deletions(-)
diff --git a/morphlib/plugins/branch_and_merge_plugin.py
b/morphlib/plugins/branch_and_merge_plugin.py
index abadf8d..84bedd3 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -107,12 +107,16 @@ class BranchAndMergePlugin(cliapp.Plugin):
with open(filename, 'w') as f:
f.write('%s\n' % repo)
- @staticmethod
- def read_branch_root(branch_dir):
- filename = os.path.join(branch_dir, '.morph-system-branch',
- 'branch-root')
- with open(filename, 'r') as f:
- return f.read().strip()
+ def set_branch_config(self, branch_dir, option, value):
+ filename = os.path.join(branch_dir, '.morph-system-branch',
'config')
+ self.app.runcmd(['git', 'config', '-f', filename,
+ 'branch.%s' % option, '%s' % value])
+
+ def get_branch_config(self, branch_dir, option):
+ filename = os.path.join(branch_dir, '.morph-system-branch',
'config')
+ value = self.app.runcmd(['git', 'config', '-f',
filename,
+ 'branch.%s' % option])
+ return value.strip()
@staticmethod
def clone_to_directory(app, dirname, reponame, ref):
@@ -280,7 +284,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
os.mkdir(os.path.join(branch_dir, '.morph-system-branch'))
# Remember the repository we branched off from.
- self.write_branch_root(branch_dir, repo)
+ self.set_branch_config(branch_dir, 'branch-root', repo)
# Clone into system branch directory.
repo_dir = os.path.join(branch_dir, self.convert_uri_to_path(repo))
@@ -326,7 +330,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
os.mkdir(os.path.join(branch_dir, '.morph-system-branch'))
# Remember the repository we branched off from.
- self.write_branch_root(branch_dir, repo)
+ self.set_branch_config(branch_dir, 'branch-root', repo)
# Clone into system branch directory.
repo_dir = os.path.join(branch_dir, self.convert_uri_to_path(repo))
@@ -343,7 +347,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
workspace = self.deduce_workspace()
system_branch = self.deduce_system_branch()
branch_dir = os.path.join(workspace, system_branch)
- branch_root = self.read_branch_root(branch_dir)
+ branch_root = self.get_branch_config(branch_dir, 'branch-root')
self.app.output.write('%s\n' % branch_root)
def merge(self, args):
@@ -378,7 +382,7 @@ class BranchAndMergePlugin(cliapp.Plugin):
# Find out which repository we branched off from.
branch_dir = os.path.join(workspace, system_branch)
- branch_root = self.read_branch_root(branch_dir)
+ branch_root = self.get_branch_config(branch_dir, 'branch-root')
# Convert it to a local directory in the branch.
branch_root_path = self.convert_uri_to_path(branch_root)
diff --git a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
index d68a634..443f325 100644
--- a/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
+++ b/tests.branching/branch-creates-new-system-branch-not-from-master.stdout
@@ -9,7 +9,7 @@ d ./newbranch
d ./newbranch/.morph-system-branch
d ./newbranch/baserock:morphs
d ./newbranch/baserock:morphs/.git
-f ./newbranch/.morph-system-branch/branch-root
+f ./newbranch/.morph-system-branch/config
f ./newbranch/baserock:morphs/hello-stratum.morph
f ./newbranch/baserock:morphs/hello-system.morph
f ./newbranch/baserock:morphs/this.is.alfred
diff --git a/tests.branching/branch-creates-new-system-branch.stdout
b/tests.branching/branch-creates-new-system-branch.stdout
index 3f2dba1..e79e858 100644
--- a/tests.branching/branch-creates-new-system-branch.stdout
+++ b/tests.branching/branch-creates-new-system-branch.stdout
@@ -9,7 +9,7 @@ d ./newbranch
d ./newbranch/.morph-system-branch
d ./newbranch/baserock:morphs
d ./newbranch/baserock:morphs/.git
-f ./newbranch/.morph-system-branch/branch-root
+f ./newbranch/.morph-system-branch/config
f ./newbranch/baserock:morphs/hello-stratum.morph
f ./newbranch/baserock:morphs/hello-system.morph
Current branches:
diff --git a/tests.branching/branch-works-anywhere.stdout
b/tests.branching/branch-works-anywhere.stdout
index cddc2d7..ec22698 100644
--- a/tests.branching/branch-works-anywhere.stdout
+++ b/tests.branching/branch-works-anywhere.stdout
@@ -9,7 +9,7 @@ d ./branch1
d ./branch1/.morph-system-branch
d ./branch1/baserock:morphs
d ./branch1/baserock:morphs/.git
-f ./branch1/.morph-system-branch/branch-root
+f ./branch1/.morph-system-branch/config
f ./branch1/baserock:morphs/hello-stratum.morph
f ./branch1/baserock:morphs/hello-system.morph
Workspace after creating the second branch:
@@ -27,10 +27,10 @@ d ./branch2
d ./branch2/.morph-system-branch
d ./branch2/baserock:morphs
d ./branch2/baserock:morphs/.git
-f ./branch1/.morph-system-branch/branch-root
+f ./branch1/.morph-system-branch/config
f ./branch1/baserock:morphs/hello-stratum.morph
f ./branch1/baserock:morphs/hello-system.morph
-f ./branch2/.morph-system-branch/branch-root
+f ./branch2/.morph-system-branch/config
f ./branch2/baserock:morphs/hello-stratum.morph
f ./branch2/baserock:morphs/hello-system.morph
Workspace after creating the third branch:
@@ -52,13 +52,13 @@ d ./branch3
d ./branch3/.morph-system-branch
d ./branch3/baserock:morphs
d ./branch3/baserock:morphs/.git
-f ./branch1/.morph-system-branch/branch-root
+f ./branch1/.morph-system-branch/config
f ./branch1/baserock:morphs/hello-stratum.morph
f ./branch1/baserock:morphs/hello-system.morph
-f ./branch2/.morph-system-branch/branch-root
+f ./branch2/.morph-system-branch/config
f ./branch2/baserock:morphs/hello-stratum.morph
f ./branch2/baserock:morphs/hello-system.morph
-f ./branch3/.morph-system-branch/branch-root
+f ./branch3/.morph-system-branch/config
f ./branch3/baserock:morphs/hello-stratum.morph
f ./branch3/baserock:morphs/hello-system.morph
Workspace after creating the fourth branch:
@@ -84,15 +84,15 @@ d ./branch4
d ./branch4/.morph-system-branch
d ./branch4/baserock:morphs
d ./branch4/baserock:morphs/.git
-f ./branch1/.morph-system-branch/branch-root
+f ./branch1/.morph-system-branch/config
f ./branch1/baserock:morphs/hello-stratum.morph
f ./branch1/baserock:morphs/hello-system.morph
-f ./branch2/.morph-system-branch/branch-root
+f ./branch2/.morph-system-branch/config
f ./branch2/baserock:morphs/hello-stratum.morph
f ./branch2/baserock:morphs/hello-system.morph
-f ./branch3/.morph-system-branch/branch-root
+f ./branch3/.morph-system-branch/config
f ./branch3/baserock:morphs/hello-stratum.morph
f ./branch3/baserock:morphs/hello-system.morph
-f ./branch4/.morph-system-branch/branch-root
+f ./branch4/.morph-system-branch/config
f ./branch4/baserock:morphs/hello-stratum.morph
f ./branch4/baserock:morphs/hello-system.morph
diff --git a/tests.branching/checkout-existing-branch.stdout
b/tests.branching/checkout-existing-branch.stdout
index 1af2900..4a8a614 100644
--- a/tests.branching/checkout-existing-branch.stdout
+++ b/tests.branching/checkout-existing-branch.stdout
@@ -9,7 +9,7 @@ d ./master
d ./master/.morph-system-branch
d ./master/baserock:morphs
d ./master/baserock:morphs/.git
-f ./master/.morph-system-branch/branch-root
+f ./master/.morph-system-branch/config
f ./master/baserock:morphs/hello-stratum.morph
f ./master/baserock:morphs/hello-system.morph
Current branches:
diff --git a/tests.branching/checkout-non-aliased-repos.stdout
b/tests.branching/checkout-non-aliased-repos.stdout
index 872d74a..dbaa3e5 100644
--- a/tests.branching/checkout-non-aliased-repos.stdout
+++ b/tests.branching/checkout-non-aliased-repos.stdout
@@ -12,7 +12,7 @@ d ./master/TEMP_DIR
d ./master/DATADIR
d ./master/DATADIR/morphs
d ./master/DATADIR/morphs/.git
-f ./master/.morph-system-branch/branch-root
+f ./master/.morph-system-branch/config
f ./master/DATADIR/morphs/hello-stratum.morph
f ./master/DATADIR/morphs/hello-system.morph
Current branches of repo with suffix:
@@ -31,7 +31,7 @@ d ./master/TEMP_DIR
d ./master/DATADIR
d ./master/DATADIR/morphs
d ./master/DATADIR/morphs/.git
-f ./master/.morph-system-branch/branch-root
+f ./master/.morph-system-branch/config
f ./master/DATADIR/morphs/hello-stratum.morph
f ./master/DATADIR/morphs/hello-system.morph
Current branches of repo without suffix:
diff --git a/tests.branching/checkout-works-anywhere.stdout
b/tests.branching/checkout-works-anywhere.stdout
index 0cd18b8..bb4cc1f 100644
--- a/tests.branching/checkout-works-anywhere.stdout
+++ b/tests.branching/checkout-works-anywhere.stdout
@@ -9,7 +9,7 @@ d ./master
d ./master/.morph-system-branch
d ./master/baserock:morphs
d ./master/baserock:morphs/.git
-f ./master/.morph-system-branch/branch-root
+f ./master/.morph-system-branch/config
f ./master/baserock:morphs/hello-stratum.morph
f ./master/baserock:morphs/hello-system.morph
Workspace after checking out master from within a new branch:
@@ -27,9 +27,9 @@ d ./newbranch
d ./newbranch/.morph-system-branch
d ./newbranch/baserock:morphs
d ./newbranch/baserock:morphs/.git
-f ./master/.morph-system-branch/branch-root
+f ./master/.morph-system-branch/config
f ./master/baserock:morphs/hello-stratum.morph
f ./master/baserock:morphs/hello-system.morph
-f ./newbranch/.morph-system-branch/branch-root
+f ./newbranch/.morph-system-branch/config
f ./newbranch/baserock:morphs/hello-stratum.morph
f ./newbranch/baserock:morphs/hello-system.morph
--
1.7.11.4