summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-28 15:12:30 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-08-28 16:06:16 +0000
commitbb619f5ca782ab56dbb189f0281e8afd5025ced3 (patch)
treed6f498bea2d7f18d8949f845f20bb72f86d0ce6d
parentf2415383628cb22c5646d96b0e7bbfd6d0629072 (diff)
downloadmorph-bb619f5ca782ab56dbb189f0281e8afd5025ced3.tar.gz
Create mine directory if it does not exists when running "morph init"
Until now, morph failed when the mine directory did not exist. However, there is no good reason why it can't attempt to create it.
-rw-r--r--morphlib/plugins/branch_and_merge_plugin.py9
-rw-r--r--tests.branching/init-newdir.exit1
-rwxr-xr-xtests.branching/init-newdir.script6
-rw-r--r--tests.branching/init-newdir.stderr1
-rw-r--r--tests.branching/init-newdir.stdout2
5 files changed, 12 insertions, 7 deletions
diff --git a/morphlib/plugins/branch_and_merge_plugin.py b/morphlib/plugins/branch_and_merge_plugin.py
index e5c5fb44..670b3117 100644
--- a/morphlib/plugins/branch_and_merge_plugin.py
+++ b/morphlib/plugins/branch_and_merge_plugin.py
@@ -190,13 +190,18 @@ class BranchAndMergePlugin(cliapp.Plugin):
dirname = args[0]
+ # verify the mine directory is empty (and thus, can be used) or
+ # create it if it doesn't exist yet
if os.path.exists(dirname):
if os.listdir(dirname) != []:
raise cliapp.AppException('can only initialize empty '
'directory: %s' % dirname)
else:
- raise cliapp.AppException('can only initialize an existing '
- 'empty directory: %s' % dirname)
+ try:
+ os.makedirs(dirname)
+ except:
+ raise cliapp.AppException('failed to create mine '
+ 'directory: %s' % dirname)
os.mkdir(os.path.join(dirname, '.morph'))
self.app.status(msg='Initialized morph mine', chatty=True)
diff --git a/tests.branching/init-newdir.exit b/tests.branching/init-newdir.exit
deleted file mode 100644
index d00491fd..00000000
--- a/tests.branching/init-newdir.exit
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/tests.branching/init-newdir.script b/tests.branching/init-newdir.script
index 3bb4a1ba..70c8bb87 100755
--- a/tests.branching/init-newdir.script
+++ b/tests.branching/init-newdir.script
@@ -17,8 +17,8 @@
set -eu
-# Test that "morph init" gives an error when given the name of a
-# directory that does not exist yet.
+# Test that "morph init" works if given a directory that
+# does not exist yet.
"$SRCDIR/scripts/test-morph" init "$DATADIR/foo"
-
+"$SRCDIR/scripts/list-tree" "$DATADIR/foo"
diff --git a/tests.branching/init-newdir.stderr b/tests.branching/init-newdir.stderr
deleted file mode 100644
index 066d69c0..00000000
--- a/tests.branching/init-newdir.stderr
+++ /dev/null
@@ -1 +0,0 @@
-ERROR: can only initialize an existing empty directory: TMP/foo
diff --git a/tests.branching/init-newdir.stdout b/tests.branching/init-newdir.stdout
new file mode 100644
index 00000000..e7922ee1
--- /dev/null
+++ b/tests.branching/init-newdir.stdout
@@ -0,0 +1,2 @@
+d .
+d ./.morph