git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
CEChristian Engwer <christian.engwer@wwu.de>
Date
Apr 15, 2012, 18:55 UTC
Message-ID
<20120415185535.GA9150@mathe-macht-spass.de>
In-Reply-To
<20120410211732.GB27555@dcvr.yhbt.net>
Hi!
On Tue, Apr 10, 2012 at 09:17:32PM +0000, Eric Wong wrote:
Show 9 quoted lines
> Christian Engwer <christian.engwer@wwu.de> 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@wwu.de>
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
Previous: Christian EngwerNext: Jonathan Nieder
Message 4 of 5 in “prohibit "svn dcommit" on remote-tracking-branches”
  1. prohibit "svn dcommit" on remote-tracking-branchesChristian Engwer, Apr 4, 2012
  2. Eric WongApr 10, 2012
  3. Christian EngwerApr 15, 2012
  4. Christian EngwerApr 15, 2012
  5. Jonathan NiederApr 15, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.