Skip to contentSkip to conversation

Fetch: get the remote branches to merge from the branch properties.

PATCH In review Santi Béjar 2 participants 4 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fetch: get the remote branches to merge from the branch properties.

If in branch "foo" and this in config:

[branch "foo"]
merge=bar

"git fetch": fetch from the default repository and program the "bar"
branch to be merged with pull.

---
 Documentation/config.txt |    4 ++++
 git-parse-remote.sh      |   13 ++++++++++---
 2 files changed, 14 insertions(+), 3 deletions(-)
Documentation/config.txt +4 -0
index fa20e28..b4de243 100644
@@ -122,6 +122,10 @@ apply.whitespace::
 branch.<name>.remote::
        When in branch <name>, it tells `git pull` which remote to fetch.
 
+branch.<name>.merge::
+       When in branch <name>, it tells `git fetch` the remote branch to be
+       merged.
+
 pager.color::
        A boolean to enable/disable colored output when the pager is in
        use (default is true).
git-parse-remote.sh +10 -3
index 187f088..0b14606 100755
@@ -86,9 +86,12 @@ get_remote_default_refs_for_push () {
 
 # Subroutine to canonicalize remote:local notation.
 canon_refs_list_for_fetch () {
-	# Leave only the first one alone; add prefix . to the rest
+	# Leave the branches in branch.${curr_branch}.merge alone,
+	# or the first one; add prefix . to the rest
 	# to prevent the secondary branches to be merged by default.
-	dot_prefix=
+	curr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
+	merge_branches=$(git-repo-config --get-all "branch.${curr_branch}.merge")
+	[ -z "$merge_branches" ] && merge_branches=$1
 	for ref
 	do
 		force=
@@ -101,6 +104,11 @@ canon_refs_list_for_fetch () {
 		expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
 		remote=$(expr "z$ref" : 'z\([^:]*\):')
 		local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
+		dot_prefix=.
+		for merge_branch in $merge_branches
+		do
+		    [ "$remote" = "$merge_branch" ] && dot_prefix= && break
+		done
 		case "$remote" in
 		'') remote=HEAD ;;
 		refs/heads/* | refs/tags/* | refs/remotes/*) ;;
@@ -120,7 +128,6 @@ canon_refs_list_for_fetch () {
 		   die "* refusing to create funny ref '$local_ref_name' locally"
 		fi
 		echo "${dot_prefix}${force}${remote}:${local}"
-		dot_prefix=.
 	done
 }
 
Signature · 1 line
1.4.2.1.g4b5cd
#1 lore raw
Quoted 8 lines

If in branch "foo" and this in config:

[branch "foo"]
merge=3Dbar

"git fetch": fetch from the default repository and program the "bar"
branch to be merged with pull.

Your patch has a very strange whitespace damage in it, and I am not talking about quoted-printable encoding.

Quoted 9 lines
Documentation/config.txt +0 -0
index fa20e28..b4de243 100644
@@ -122,6 +122,10 @@ apply.whitespace::
 branch.<name>.remote::
        When in branch <name>, it tells `git pull` which remote to fetc=

h.

A tab in context before "When" is expanded into spaces, and the empty line in the context does not have the leading SP.

Documentation/config.txt apply.whitespace:: · line 128

Quoted 5 lines
Documentation/config.txt +2 -0
+branch.<name>.merge::
+       When in branch <name>, it tells `git fetch` the remote branch t=

o be

Documentation/config.txt +2 -0
+       merged.
+

I suspect you wanted to start the new line with a leading tab before "When" but it is expanded into spaces here.

However, the diff for the other file in the same patch does not have this problem.

No need to resend, as I hand-applied it to a new topic, but I am a bit curious why one diff is broken when the other one is not in the same e-mail message.

author
#2 lore raw
Quoted 2 lines

Your patch has a very strange whitespace damage in it, and I am not talking about quoted-printable encoding.

Last minute hand-editing, sorry. Did I already say it is very late here? :(

Santi

author
#3 lore raw
In reply to Santi Béjar

2006/9/23, Santi Béjar <[email protected]>:

Quoted 9 lines

If in branch "foo" and this in config:

[branch "foo"]
merge=bar

"git fetch": fetch from the default repository and program the "bar"
branch to be merged with pull.

Just to comments (it's late here):

.- the branch.foo.merge must be the same as specified in the remotes/$remote.

.- I've already found a bug (it's late and I need to sleep, sorry). This must only be done for the default repository (origin, or in branch.foo.remote).

Santi