[PATCH v2] nmbug: Add an 'init' command

W. Trevor King wking at tremily.us
Fri Oct 10 11:31:25 PDT 2014


For folks that want to start versioning a new tag-space, instead of
cloning one that someone else has already started.

The empty-blob hash-object call avoids errors like:

  $ nmbug commit
  error: invalid object 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 for
'tags/...'
  fatal: git-write-tree: error building trees
  'git HASH(0x9ef3eb8) write-tree' exited with nonzero value

David Bremner suggested [1]:

  $ git hash-object -w /dev/null

instead of my Python version of:

  $ git hash-object -w --stdin <&-

but I expect that closing stdin is more portable than the /dev/null
path.

[1]: id:87y4vu6uvf.fsf at maritornes.cs.unb.ca
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
---
This is just like v1 [1], but rebased into the new Python nmbug.  I'd
initially supported the /dev/null approach [2], but have since gone
back to my original --stdin approach for the empty blob object (as
explained in the commit message).  Sorry for waffling ;).

Cheers,
Trevor

[1]: id:05ccd672f55444f74da62250e2305fb84fdc6c42.1404678709.git.wking at tremily.us
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18630
[2]: id:20140716001239.GH30232 at odin
     http://article.gmane.org/gmane.mail.notmuch.general/18722
 devel/nmbug/nmbug | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index 9402ead..23bac5c 100755
--- a/devel/nmbug/nmbug
+++ b/devel/nmbug/nmbug
@@ -373,6 +373,29 @@ def fetch(remote=None):
     _git(args=args, wait=True)
 
 
+def init(remote=None):
+    """
+    Create an empty nmbug repository.
+
+    This wraps 'git init' with a few extra steps to support subsequent
+    status and commit commands.
+    """
+    with _tempfile.TemporaryDirectory(prefix='nmbug-init.') as workdir:
+        _spawn(
+            args=['git', 'init', '--separate-git-dir', NMBGIT, workdir],
+            wait=True)
+        _git(args=['config', '--unset', 'core.worktree'], wait=True)
+        _git(args=['config', 'core.bare', 'true'], wait=True)
+        # create an empty blob (e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
+        _git(args=['hash-object', '-w', '--stdin'], input='', wait=True)
+        _git(
+            args=[
+                'commit', '--allow-empty', '-m', 'Start a new nmbug repository'
+                ],
+            additional_env={'GIT_WORK_TREE': workdir},
+            wait=True)
+
+
 def checkout():
     """
     Update the notmuch database from Git.
@@ -703,6 +726,7 @@ if __name__ == '__main__':
             'clone',
             'commit',
             'fetch',
+            'init',
             'log',
             'merge',
             'pull',
-- 
2.1.0.60.g85f0837



More information about the notmuch mailing list