unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v4] nmbug: Add an 'init' command
@ 2015-01-19  0:40 W. Trevor King
  2015-01-19  9:44 ` Tomi Ollila
  0 siblings, 1 reply; 3+ messages in thread
From: W. Trevor King @ 2015-01-19  0:40 UTC (permalink / raw)
  To: notmuch

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 (which doesn't exist on Windows, for example).

The --bare init and use of NMBGIT as the work tree (what could go
wrong with an empty commit?) are suggestions from Michal Sojka [2].

[1]: id:87y4vu6uvf.fsf@maritornes.cs.unb.ca
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
[2]: id:87a93a5or2.fsf@resox.2x.cz
     http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19767
---
Since v3 [1] I've incorporated Michal's suggestions [2]:

* Start with 'git --git-dir {NMBGIT} init --bare
* Use NMBGIT instead of a temporary workdir when creating the initial
  “Start a new nmbug repository” commit.

As well as the core.logallrefupdates tweak I turned up in testing [3].

[1]: id:113512958b3fd64902517c1c55576faef816f852.1414532174.git.wking@tremily.us
     http://thread.gmane.org/gmane.mail.notmuch.general/19495
[2]: id:87a93a5or2.fsf@resox.2x.cz
     http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19767
[3]: id:20141129201829.GI4062@odin.tremily.us
     http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19774

 devel/nmbug/nmbug | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index 932ec12..1297345 100755
--- a/devel/nmbug/nmbug
+++ b/devel/nmbug/nmbug
@@ -374,6 +374,25 @@ 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.
+    """
+    _spawn(args=['git', '--git-dir', NMBGIT, 'init', '--bare'], wait=True)
+    _git(args=['config', 'core.logallrefupdates', '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': NMBGIT},
+        wait=True)
+
+
 def checkout():
     """
     Update the notmuch database from Git.
@@ -725,6 +744,7 @@ if __name__ == '__main__':
             'commit',
             'fetch',
             'help',
+            'init',
             'log',
             'merge',
             'pull',
-- 
2.1.0.60.g85f0837

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] nmbug: Add an 'init' command
  2015-01-19  0:40 [PATCH v4] nmbug: Add an 'init' command W. Trevor King
@ 2015-01-19  9:44 ` Tomi Ollila
  2015-01-19 16:55   ` W. Trevor King
  0 siblings, 1 reply; 3+ messages in thread
From: Tomi Ollila @ 2015-01-19  9:44 UTC (permalink / raw)
  To: W. Trevor King, notmuch

On Mon, Jan 19 2015, "W. Trevor King" <wking@tremily.us> wrote:

> 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 (which doesn't exist on Windows, for example).

I agree with this...

I attempted to try this (being stup^H^H^H^Hadventurous and not backupping
~/.nmbug -- should the existence be checked first ???) and got the following ;/

$ python2.7 devel/nmbug/nmbug init
Reinitialized existing Git repository in /home/too/.nmbug/
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
user.name not defined
[u'git', u'--git-dir', u'/home/too/.nmbug', u'commit', u'--allow-empty',
u'-m', u'Start a new nmbug repository'] exited with 1
zsh: exit 1     python2.7 devel/nmbug/nmbug init

This is due to my default /path/to/git-templates/pre-commit forbidding
commits unless I've configured user.name & user.email for that particular
repository....

I guess there is not much one can do to handle users' mystic global
hooks -- I'll look (later) whether e.g. '--no-hooks' parameter could be given
to nmbug from command line...

... Ok, it was --no-verify and patching that to the command line worked --
git complained that "Your name and email address were configured
automatically based on your username and hostname..." but commit succeeded :).

... but Now I issued nmbug init twice. now there are 2 

    Start a new nmbug repository

commits. I think it should be checked so that init on already-existing
repository does not succeed.


Tomi

>
> The --bare init and use of NMBGIT as the work tree (what could go
> wrong with an empty commit?) are suggestions from Michal Sojka [2].
>
> [1]: id:87y4vu6uvf.fsf@maritornes.cs.unb.ca
>      http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
> [2]: id:87a93a5or2.fsf@resox.2x.cz
>      http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19767
> ---
> Since v3 [1] I've incorporated Michal's suggestions [2]:
>
> * Start with 'git --git-dir {NMBGIT} init --bare
> * Use NMBGIT instead of a temporary workdir when creating the initial
>   “Start a new nmbug repository” commit.
>
> As well as the core.logallrefupdates tweak I turned up in testing [3].
>
> [1]: id:113512958b3fd64902517c1c55576faef816f852.1414532174.git.wking@tremily.us
>      http://thread.gmane.org/gmane.mail.notmuch.general/19495
> [2]: id:87a93a5or2.fsf@resox.2x.cz
>      http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19767
> [3]: id:20141129201829.GI4062@odin.tremily.us
>      http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19774
>
>  devel/nmbug/nmbug | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
> index 932ec12..1297345 100755
> --- a/devel/nmbug/nmbug
> +++ b/devel/nmbug/nmbug
> @@ -374,6 +374,25 @@ 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.
> +    """
> +    _spawn(args=['git', '--git-dir', NMBGIT, 'init', '--bare'], wait=True)
> +    _git(args=['config', 'core.logallrefupdates', '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': NMBGIT},
> +        wait=True)
> +
> +
>  def checkout():
>      """
>      Update the notmuch database from Git.
> @@ -725,6 +744,7 @@ if __name__ == '__main__':
>              'commit',
>              'fetch',
>              'help',
> +            'init',
>              'log',
>              'merge',
>              'pull',
> -- 
> 2.1.0.60.g85f0837

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] nmbug: Add an 'init' command
  2015-01-19  9:44 ` Tomi Ollila
@ 2015-01-19 16:55   ` W. Trevor King
  0 siblings, 0 replies; 3+ messages in thread
From: W. Trevor King @ 2015-01-19 16:55 UTC (permalink / raw)
  To: Tomi Ollila; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 2751 bytes --]

On Mon, Jan 19, 2015 at 11:44:16AM +0200, Tomi Ollila wrote:
> $ python2.7 devel/nmbug/nmbug init
> Reinitialized existing Git repository in /home/too/.nmbug/
> e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
> user.name not defined
> [u'git', u'--git-dir', u'/home/too/.nmbug', u'commit', u'--allow-empty',
> u'-m', u'Start a new nmbug repository'] exited with 1
> zsh: exit 1     python2.7 devel/nmbug/nmbug init
> 
> This is due to my default /path/to/git-templates/pre-commit
> forbidding commits unless I've configured user.name & user.email for
> that particular repository....
> 
> I guess there is not much one can do to handle users' mystic global
> hooks -- I'll look (later) whether e.g. '--no-hooks' parameter could
> be given to nmbug from command line...
> 
> ... Ok, it was --no-verify and patching that to the command line
> worked -- git complained that "Your name and email address were
> configured automatically based on your username and hostname..."…

Hmm.  My initial feeling is that if your pre-commit hook doesn't want
you to commit, we should respect that.  Although I'm not sure how to
handle this case for folks like you that don't define a global
username or email address.  Possibilities:

* Drop the empty commit from ‘nmbug init’ and teach ‘nmbug log’,
  ‘status’, ‘commit’, etc. to handle the “we don't have any commits
  yet” case?  That gives you time between the init and first commit to
  go into the repository and setup your username and email address by
  hand.  This would be the most work, but gives us a more native
  solution (‘nmbug init’ maps more directly to ‘git init’).

* Adjust the syntax to:

    nmbug init -- {arguments passed through to ‘git commit’}

  so you could run:

    nmbug init -- --author 'A U Thor <author@example.com>'

  or:

    nmbug init -- --no-verify

  this works as long as the tweak you need is accessible from a ‘git
  commit’ argument (I guess --no-verify covers us there).

> … but commit succeeded :).

From the template pre-commit.sample:

  The hook should exit with non-zero status after issuing an
  appropriate message if it wants to stop the commit.

so you should check that your hook is doing that if you expect to
abort commits it doesn't like ;).

> I think it should be checked so that init on already-existing
> repository does not succeed.

Good point.  I've added:

  if _os.path.exists(NMBGIT):
      raise ValueError('NMBGIT path ({!r}) already exists'.format(NMBGIT))

for v5.

Cheers,
Trevor

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-01-19 17:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-19  0:40 [PATCH v4] nmbug: Add an 'init' command W. Trevor King
2015-01-19  9:44 ` Tomi Ollila
2015-01-19 16:55   ` W. Trevor King

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).