git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] git svn : hook before 'git svn dcommit'
@ 2011-08-15 20:04 Frédéric Heitzmann
  2011-08-15 21:14 ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Frédéric Heitzmann @ 2011-08-15 20:04 UTC (permalink / raw)
  To: gitster; +Cc: git, Frédéric Heitzmann

The 'pre-svn-dcommit' hook is called before 'git svn dcommit', which aborts
if return value is not zero. The only parameter given to the hook is the
reference given to 'git svn dcommit'. If no paramter was used, hook gets HEAD
as its only parameter.

Signed-off-by: Frédéric Heitzmann <frederic.heitzmann@gmail.com>
---
I resend the same patch previously sent July 9th.
Apparently it did not graduated upstream, and I do not know why.
Please someone tell me if something needs to be improved.

 Documentation/git-svn.txt |   14 +++++++++++++-
 git-svn.perl              |   21 +++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 713e523..ec87ed3 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -700,6 +700,18 @@ section because they affect the 'git-svn-id:' metadata line, except
 for rewriteRoot and rewriteUUID which can be used together.
 
 
+HOOKS
+-----
+
+The 'pre-svn-dcommit' hook is called by 'git svn dcommit' and can be used to
+prevent some diff to be committed to a SVN repository. It may typically be
+used to filter some intermediate patches, which were committed into git but
+must not find their way to the SVN repository.
+
+It takes a single parameter, the reference given to 'git svn dcommit'. If the
+hook exists with a non zero-status, 'git svn dcommit' will abort.
+
+
 BASIC EXAMPLES
 --------------
 
@@ -901,7 +913,7 @@ reset) branches-maxRev and/or tags-maxRev as appropriate.
 
 SEE ALSO
 --------
-linkgit:git-rebase[1]
+linkgit:git-rebase[1], linkgit:githooks[5]
 
 GIT
 ---
diff --git a/git-svn.perl b/git-svn.perl
index 89f83fd..a537858 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -396,6 +396,25 @@ sub init_subdir {
 	$_repository = Git->repository(Repository => $ENV{GIT_DIR});
 }
 
+sub pre_svn_dcommit_hook {
+	my $head = shift;
+
+	my $hook = "$ENV{GIT_DIR}/hooks/pre-svn-dcommit";
+	return 0 if ! -e $hook || ! -x $hook;
+
+	system($hook, $head);
+	if ($? == -1) {
+		print "[pre_svn_dcommit_hook] failed to execute $hook: $!\n";
+		return 1;
+	} elsif ($? & 127) {
+		printf "[pre_svn_dcommit_hook] child died with signal %d, %s coredump\n",
+		($? & 127),  ($? & 128) ? 'with' : 'without';
+		return 1;
+	} else {
+		return $? >> 8;
+	}
+}
+
 sub cmd_clone {
 	my ($url, $path) = @_;
 	if (!defined $path &&
@@ -505,6 +524,8 @@ sub cmd_dcommit {
 		. "or stash them with `git stash'.\n";
 	$head ||= 'HEAD';
 
+	return if pre_svn_dcommit_hook($head);
+
 	my $old_head;
 	if ($head ne 'HEAD') {
 		$old_head = eval {
-- 
1.7.6.133.gd3b55a

^ permalink raw reply related	[flat|nested] 11+ messages in thread
* Re: [PATCH] git svn : hook before 'git svn dcommit'
@ 2011-07-04  5:54 Frédéric Heitzmann
  2011-07-05 20:44 ` [PATCH v2] " Frédéric Heitzmann
  0 siblings, 1 reply; 11+ messages in thread
From: Frédéric Heitzmann @ 2011-07-04  5:54 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git



Le 03/07/2011 23:00, Matthieu Moy a écrit :
> Frédéric Heitzmann<frederic.heitzmann@gmail.com>  writes:
>
>> The 'pre-svn-dcommit' hook is called by 'git svn dcommit' and can be used to
>> prevent some diff to be committed to a SVN repository. It may typically be
>> used to filter some intermediate patches, which were committed into git but
>> must not find their way to the SVN repository.
> Why 2 patches?
>
> We usually try to have each commit as correct as possible (e.g. when
> sending several patches, each commit should still pass the testsuite).
> With your 2-patches serie, the first commit has documentation for a
> feature which doesn't exist yet.
I find it easier to separate commits on documentation from code patch, 
especially for rereading and dicussing.
However, if it is desirable to get them merged, I could do that easily.

As for the order :
patch 1/2 : perl magic
patch 2/2 : documentation update
=>  the serie looks in the right order to me.

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

end of thread, other threads:[~2011-09-01 17:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-15 20:04 [PATCH v2] git svn : hook before 'git svn dcommit' Frédéric Heitzmann
2011-08-15 21:14 ` Junio C Hamano
2011-08-17  0:30   ` Eric Wong
     [not found]     ` <CALeToSWJNK=q4iPwxNvgGin0T61oLKJd=b9F3cSSo0vVebrhhQ@mail.gmail.com>
2011-08-17 14:35       ` Frédéric Heitzmann
2011-08-17 20:37         ` Eric Wong
2011-08-18 13:43           ` Frédéric Heitzmann
2011-08-20 18:41             ` Eric Wong
2011-08-18  9:12         ` Peter Baumann
2011-09-01 16:58           ` Paul Young
  -- strict thread matches above, loose matches on Subject: below --
2011-07-04  5:54 [PATCH] " Frédéric Heitzmann
2011-07-05 20:44 ` [PATCH v2] " Frédéric Heitzmann
2011-07-09 12:18   ` Frédéric Heitzmann

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 NNTP newsgroup(s).