public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Paolo Bonzini <paolo.bonzini@lu•unisi.ch>
To: Johannes Schindelin <Johannes.Schindelin@gmx•de>
Cc: Julian Phillips <julian@quantumfyre•co.uk>,
	Andy Parkins <andyparkins@gmail•com>,
	git@vger•kernel.org
Subject: Re: defaults for where to merge from
Date: Wed, 28 Feb 2007 18:11:16 +0100	[thread overview]
Message-ID: <45E5B7B4.9080605@lu.unisi.ch> (raw)
In-Reply-To: <Pine.LNX.4.63.0702281643200.22628@wbgn013.biozentrum.uni-wuerzburg.de>

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


> I don't think that you should be forced to do it explicitely. If you want 
> to merge in another branch, you can do that _explicitely_. So, defaulting 
> to what most people want anyway is A Good Thing.

Here is a prototype patch to implement this functionality.  One problem 
is that config.c does not remove cleaned sections, so after "git-branch 
-d mybranch" one is left with a useless "[branch "mybranch"]" section in 
.git/config.  Other than this, it seems to work well in my experiments.

Paolo

[-- Attachment #2: git-builtin-branch-config.patch --]
[-- Type: text/plain, Size: 2528 bytes --]

diff --git a/builtin-branch.c b/builtin-branch.c
index d0179b0..4c42825 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -147,8 +147,21 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
 			error("Error deleting %sbranch '%s'", remote,
 			       argv[i]);
 			ret = 1;
-		} else
+		} else {
+			if (kinds == REF_LOCAL_BRANCH) {
+				/* Remove git-config keys.  */
+				char *config_key = xmalloc(strlen(argv[i]) + 15);
+				sprintf(config_key, "branch.%s.remote", argv[i]);
+				git_config_set(config_key, NULL);
+
+				sprintf(config_key, "branch.%s.merge", argv[i]);
+				git_config_set(config_key, NULL);
+				sprintf(config_key, "branch.%s", argv[i]);
+				git_config_set(config_key, NULL);
+			}
+
 			printf("Deleted %sbranch %s.\n", remote, argv[i]);
+		}
 
 	}
 
@@ -316,7 +330,7 @@ static void create_branch(const char *name, const char *start_name,
 	struct commit *commit;
 	unsigned char sha1[20];
 	char ref[PATH_MAX], msg[PATH_MAX + 20];
-	int forcing = 0;
+	int forcing = 0, remote = 0;
 
 	snprintf(ref, sizeof ref, "refs/heads/%s", name);
 	if (check_ref_format(ref))
@@ -335,6 +349,13 @@ static void create_branch(const char *name, const char *start_name,
 		hashcpy(sha1, start_sha1);
 	else if (get_sha1(start_name, sha1))
 		die("Not a valid object name: '%s'.", start_name);
+	else {
+		unsigned char remote_sha1[20];
+		remote = strchr(start_name, '/')
+			 && read_ref(mkpath("refs/remotes/%s", start_name),
+				     remote_sha1) != -1
+			 && !memcmp(sha1, remote_sha1, 20);
+	}
 
 	if ((commit = lookup_commit_reference(sha1)) == NULL)
 		die("Not a valid branch point: '%s'.", start_name);
@@ -354,6 +375,23 @@ static void create_branch(const char *name, const char *start_name,
 		snprintf(msg, sizeof msg, "branch: Created from %s",
 			 start_name);
 
+	if (remote) {
+		/* Branching off a remote branch.  Set up so that git-pull
+		   automatically merges from there.  */
+		char *config_key = xmalloc(strlen(name) + 15);
+		char *merge_value = xmalloc(strlen(start_name) + 10);
+		char *slash = strchr(start_name, '/');
+
+		char *remote_value = xstrdup(start_name);
+		remote_value[slash - start_name] = 0;
+		sprintf(config_key, "branch.%s.remote", name);
+		git_config_set(config_key, remote_value);
+
+		sprintf(merge_value, "refs/heads/%s", slash + 1);
+		sprintf(config_key, "branch.%s.merge", name);
+		git_config_set(config_key, merge_value);
+	}
+
 	if (write_ref_sha1(lock, sha1, msg) < 0)
 		die("Failed to write ref: %s.", strerror(errno));
 }

  reply	other threads:[~2007-02-28 17:11 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-28 14:53 defaults for where to merge from Paolo Bonzini
2007-02-28 15:13 ` Johannes Schindelin
2007-02-28 15:22 ` Andy Parkins
2007-02-28 15:30   ` Paolo Bonzini
2007-02-28 15:43     ` Andy Parkins
2007-02-28 15:30   ` Julian Phillips
2007-02-28 15:46     ` Johannes Schindelin
2007-02-28 17:11       ` Paolo Bonzini [this message]
2007-02-28 18:06         ` Johannes Schindelin
2007-03-01  7:52           ` [PATCH] defaults for where to merge from (take 2) Paolo Bonzini
2007-02-28 18:45       ` defaults for where to merge from Alex Riesen
2007-02-28 19:56         ` Paolo Bonzini
2007-03-01  0:07           ` Alex Riesen
2007-03-01  1:25             ` Johannes Schindelin
2007-03-01  7:55               ` Alex Riesen
2007-03-01  8:02                 ` Paolo Bonzini
2007-03-01  8:10                   ` Alex Riesen
2007-03-01  8:18                     ` Junio C Hamano
2007-03-02 15:53                       ` J. Bruce Fields
2007-03-01  8:29                     ` Paolo Bonzini
2007-03-01  8:33                       ` Alex Riesen
2007-03-01  8:45                         ` Paolo Bonzini
2007-03-01  8:59                           ` Alex Riesen
2007-03-01  9:37                             ` [PATCH] defaults for where to merge from (take 3) Paolo Bonzini
2007-03-01 10:12                               ` Alex Riesen
2007-03-01 10:17                                 ` Paolo Bonzini
2007-03-01 10:27                                 ` Junio C Hamano
2007-03-01 10:42                                   ` Alex Riesen
2007-03-02  4:49                                     ` Junio C Hamano
2007-03-02  9:05                                       ` Alex Riesen
2007-03-02  9:57                                         ` Junio C Hamano
2007-03-01 10:47                                   ` Alex Riesen
2007-03-01 16:33                                   ` [PATCH] defaults for where to merge from (take 3, inline) Paolo Bonzini
2007-03-01 22:01                                     ` Johannes Schindelin
2007-03-02  8:10                                       ` Paolo Bonzini
2007-03-02  8:50                                         ` [PATCH, 4th version] git-branch: register where to merge from, when branching off a remote branch Paolo Bonzini
2007-03-02  9:52                                           ` Junio C Hamano
2007-03-02  9:55                                             ` Junio C Hamano
2007-03-02 10:32                                             ` Jeff King
2007-03-02 11:15                                               ` Paolo Bonzini
2007-03-02 11:21                                                 ` Jeff King
2007-03-02 11:14                                             ` Paolo Bonzini
2007-03-02 15:54                                               ` Johannes Schindelin
2007-03-02 16:33                                                 ` Paolo Bonzini
2007-03-02 19:06                                                   ` Johannes Schindelin
2007-03-02 11:19                                         ` [PATCH] defaults for where to merge from (take 3, inline) Johannes Schindelin
2007-03-02 14:10                                       ` Jakub Narebski
2007-02-28 17:31   ` defaults for where to merge from Peter Baumann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45E5B7B4.9080605@lu.unisi.ch \
    --to=paolo.bonzini@lu$(echo .)unisi.ch \
    --cc=Johannes.Schindelin@gmx$(echo .)de \
    --cc=andyparkins@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=julian@quantumfyre$(echo .)co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox