summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-31 14:59:35 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-31 15:06:56 +0000
commit6935a3db514f1552c2ffd4d24b6521bb185dcd73 (patch)
tree61131d3f43a1856e7b84b61a7520265d30539747
parentdfd41a201e9d7efd3e98653e94c11434302fe7a4 (diff)
downloadmorph-6935a3db514f1552c2ffd4d24b6521bb185dcd73.tar.gz
Use git config to store the branch root in .morph-system-branch/config
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.
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py24
-rw-r--r--tests.branching/branch-creates-new-system-branch-not-from-master.stdout2
-rw-r--r--tests.branching/branch-creates-new-system-branch.stdout2
-rw-r--r--tests.branching/branch-works-anywhere.stdout20
-rw-r--r--tests.branching/checkout-existing-branch.stdout2
-rw-r--r--tests.branching/checkout-non-aliased-repos.stdout4
-rw-r--r--tests.branching/checkout-works-anywhere.stdout6
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 abadf8da..84bedd36 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 d68a6342..443f325b 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 3f2dba1d..e79e8588 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 cddc2d76..ec22698f 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 1af2900c..4a8a614b 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 872d74aa..dbaa3e5c 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 0cd18b85..bb4cc1fa 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