Make target on publish if necessary
2 files changed, 19 insertions(+), 3 deletions(-)

M dss.py
M test.py
M dss.py +9 -2
@@ 61,7 61,12 @@ class DeadSimpleSite(object):
 
     def _git(self, *args):
         with open(os.devnull, 'w') as devnull:
-            return subprocess.check_output(('git',) + args, stderr=subprocess.STDOUT, cwd=self.target)
+            if args[0] == 'push':
+                # Git reads username and password from console, so don't suppress output
+                # Also, don't want to throw an error since most likely the user just mistyped
+                subprocess.call(('git',) + args)
+            else:
+                return subprocess.check_output(('git',) + args, stderr=subprocess.STDOUT, cwd=self.target)
 
     def _render(self, source, template):
         relpath = path.relpath(source, self.source)

          
@@ 184,6 189,8 @@ class DeadSimpleSite(object):
             self._git('--version')
         except subprocess.CalledProcessError as e:
             raise GitError('No git command found. Is git installed and on the path?')
+        if not path.exists(self.target):
+            os.makedirs(self.target)
         self._clean()
         try:
             gitdir = self._git('rev-parse', '--git-dir')

          
@@ 206,7 213,7 @@ class DeadSimpleSite(object):
             self.compile()
             self._git('add', '-A')
             self._git('commit', '-m', 'Dead Simple Site auto publish')
-            self._git('push', '-u', 'gh-pages', 'gh-pages')
+            self._git('push', '-u', 'origin', 'gh-pages')
         except subprocess.CalledProcessError as e:
             raise GitError(e)
 

          
M test.py +10 -1
@@ 124,7 124,7 @@ class TestPublish(unittest.TestCase):
         ('pull',),
         ('add', '-A'),
         ('commit', '-m', 'Dead Simple Site auto publish'),
-        ('push', '-u', 'gh-pages', 'gh-pages',)]
+        ('push', '-u', 'origin', 'gh-pages',)]
     clone_commands = prep_commands \
         + [('clone', 'https://example.com/user/repo.git', '.'), ('reset', '--hard')] \
         + update_commands

          
@@ 133,17 133,22 @@ class TestPublish(unittest.TestCase):
 
     def setUp(self):
         self._real_git = DeadSimpleSite._git
+
         self.fail_git = None
         self.gitdir = '.git'
         self.site = DeadSimpleSite('test')
         self.git_invocations = []
+
+        clean('test/_site')
         self.site.compile() # make sure the output dir does not start clean, to test cleanup
+
         def git(site, *gitargs):
             self.git_invocations.append(gitargs)
             if (gitargs[0] == self.fail_git):
                 self.fail_git = None
                 raise subprocess.CalledProcessError('foo', 'bar', 'baz')
             if (gitargs == ('rev-parse', '--git-dir')):
+                self.assertTrue(path.exists(self.site.target))
                 return self.gitdir
             if (gitargs[0] == 'clone'):
                 self.assertTrue(gitargs[1] != None)

          
@@ 156,6 161,10 @@ class TestPublish(unittest.TestCase):
     def tearDown(self):
         DeadSimpleSite._git = self._real_git
 
+    def test_creates_target(self):
+        clean('test/_site')
+        self.site.publish()
+
     def test_no_git(self):
         self.fail_git = '--version'
         with self.assertRaisesRegexp(dss.GitError, 'No git command found'):