X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=devel%2Fnmbug%2Fnmbug;h=998ee6b4b0d083467617dff92c1eab78132ce2d3;hb=567aab405b05d9ef79ddf1b62302806b9ddbeaad;hp=90d98b63cc30faa82e6cae364cbbf4fe97c6f7ee;hpb=16bf7b4b89b5ceb7f13ed318051ecd7c629d582b;p=notmuch diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug index 90d98b63..998ee6b4 100755 --- a/devel/nmbug/nmbug +++ b/devel/nmbug/nmbug @@ -26,6 +26,7 @@ my $ESCAPED_RX = qr{$ESCAPE_CHAR([A-Fa-f0-9]{2})}; my %command = ( archive => \&do_archive, checkout => \&do_checkout, + clone => \&do_clone, commit => \&do_commit, fetch => \&do_fetch, help => \&do_help, @@ -62,13 +63,20 @@ sub git_pipe { spawn ($envref, defined $ioref ? $ioref : (), defined $dir ? $dir : (), @_); } -sub git { +sub git_with_status { my $fh = git_pipe (@_); my $str = join ('', <$fh>); - unless (close $fh) { + close $fh; + my $status = $?; + chomp($str); + return ($str, $status); +} + +sub git { + my ($str, $status) = git_with_status (@_); + if ($status) { die "'git @_' exited with nonzero value\n"; } - chomp($str); return $str; } @@ -125,6 +133,16 @@ sub do_archive { system ('git', "--git-dir=$NMBGIT", 'archive', 'HEAD'); } +sub do_clone { + my $repository = shift; + + my $tempwork = tempdir ('/tmp/nmbug-clone.XXXXXX', CLEANUP => 1); + system ('git', 'clone', '--no-checkout', '--separate-git-dir', $NMBGIT, + $repository, $tempwork) == 0 + or die "'git clone' exited with nonzero value\n"; + git ('config', '--unset', 'core.worktree'); + git ('config', 'core.bare', 'true'); +} sub is_committed { my $status = shift; @@ -332,21 +350,24 @@ To discard your changes, run 'nmbug checkout' sub do_pull { my $remote = shift || 'origin'; + my $branch = shift || 'master'; git ( 'fetch', $remote); - do_merge (); + do_merge ("$remote/$branch"); } sub do_merge { + my $commit = shift || '@{upstream}'; + insist_committed (); my $tempwork = tempdir ('/tmp/nmbug-merge.XXXXXX', CLEANUP => 1); git ( { GIT_WORK_TREE => $tempwork }, 'checkout', '-f', 'HEAD'); - git ( { GIT_WORK_TREE => $tempwork }, 'merge', 'FETCH_HEAD'); + git ( { GIT_WORK_TREE => $tempwork }, 'merge', $commit); do_checkout (); } @@ -407,11 +428,13 @@ sub do_status { sub is_unmerged { + my $commit = shift || '@{upstream}'; - return 0 if (! -f $NMBGIT.'/FETCH_HEAD'); - - my $fetch_head = git ('rev-parse', 'FETCH_HEAD'); - my $base = git ( 'merge-base', 'HEAD', 'FETCH_HEAD'); + my ($fetch_head, $status) = git_with_status ('rev-parse', $commit); + if ($status) { + return 0; + } + my $base = git ( 'merge-base', 'HEAD', $commit); return ($base ne $fetch_head); @@ -473,7 +496,7 @@ sub diff_index { sub diff_refs { my $filter = shift; my $ref1 = shift || 'HEAD'; - my $ref2 = shift || 'FETCH_HEAD'; + my $ref2 = shift || '@{upstream}'; my $fh= git_pipe ( 'diff', "--diff-filter=$filter", '--name-only', $ref1, $ref2); @@ -561,10 +584,11 @@ git. Any extra arguments are used (one per line) as a commit message. push local nmbug git state to remote repo -=item B [remote] +=item B [remote] [branch] pull (merge) remote repo changes to notmuch. B is equivalent to -B followed by B. +B followed by B. The default remote is C, and +the default branch is C. =back @@ -572,6 +596,12 @@ B followed by B. =over 8 +=item B repository + +Create a local nmbug repository from a remote source. This wraps +C, adding some options to avoid creating a working tree +while preserving remote-tracking branches and upstreams. + =item B Update the notmuch database from git. This is mainly useful to discard @@ -589,12 +619,12 @@ print help [for subcommand] =item B [parameters] A simple wrapper for git log. After running C, you can -inspect the changes with C +inspect the changes with C -=item B +=item B [commit] -Merge changes from FETCH_HEAD into HEAD, and load the result into -notmuch. +Merge changes from C into HEAD, and load the result into +notmuch. The default commit is C<@{upstream}>. =item B