Re: [PATCH] prohibit "svn dcommit" on remote-tracking-branches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On Tue, Apr 10, 2012 at 09:17:32PM +0000, Eric Wong wrote:
> Christian Engwer <christian.engwer@xxxxxx> wrote:
> > A branch should either be a local copy of an svn branch, or a remote
> > tracking branch. After a "git svn dcommit" a remote tracking branch
> > could not be synced with the git remote due to the rebase that occured
> > during the dcommit. Thus we check for a remote entry in the git config
> > for the current branch and prohibit the "dcommit" if such an entry
> > exists.
> 
> Should there be an option to force/override this?

As stated there is the alternative idea to use pre-dcommit-hook.

I prepared an updated version which behaves as follows:

a) prohibit commit if a remote-tracking branch is used
b) allow commit if --commit-url is used
c) allow commit if the allow-dcommit flag is true in .git/config

Please give comments...

<snip/>

Cheers
Christian

>From 1e1e151c358b9a8c472e70eaf7aa3f6855554f6c Mon Sep 17 00:00:00 2001
From: Christian Engwer <christian.engwer@xxxxxx>
Date: Sun, 15 Apr 2012 19:27:55 +0200
Subject: [PATCH] prohibit "svn dcommit" on remote-tracking-branches

A branch should either be a local copy of an svn branch, or a remote
tracking branch. After a "git svn dcommit" a remote tracking branch
could not be synced with the git remote due to the rebase that occured
during the dcommit. Thus we check for a remote entry in the git config
for the current branch and prohibit the "dcommit" if such an entry
exists.

This behaviour can be overwritten by either providing an explicit commit url
on the command line via "--commit-url" or by setting branch.${branch}.allow-dcommit
to true.
---
 git-svn.perl |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/git-svn.perl b/git-svn.perl
index 4334b95..4a334b9 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -759,6 +759,30 @@ sub cmd_dcommit {
 		'Cannot dcommit with a dirty index.  Commit your changes first, '
 		. "or stash them with `git stash'.\n";
 	$head ||= 'HEAD';
+	my ($branches,$ctx) = eval { command_output_pipe('branch') };
+	my $branch = undef;
+	while (<$branches>) {
+		chomp;
+		if (s/^\* +//) {
+			$branch = $_;
+		}
+	}
+	command_close_pipe($branches, $ctx);
+
+	my $allowdcommit = eval { command_oneline('config', '--get',
+										      "branch.${branch}.allow-dcommit") };
+
+	if ((! defined $_commit_url) and $allowdcommit ne 'true') {
+		my $remote = eval { command_oneline('config', '--get',
+										  "branch.${branch}.remote") };
+		if ($remote) {
+			die "You specified a non-svn remote for branch ${branch}.\n".
+				"To commit to an svn repository, you can either remove the\n".
+				"  \"branch.${branch}.remote\" entry, or explicitly set a commit url\n".
+				"  on the command-line via \"--commit-url\" or override the bahavior\n".
+				"  by setting \"branch.${branch}.allow-dcommit = true\" via git config";
+		}
+	}
 
 	my $old_head;
 	if ($head ne 'HEAD') {
-- 
1.7.9.5


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]