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. Signed-off-by: Santi Béjar <sbejar@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Santi Béjar committed
Sep 23, 2006 at 22:53 UTC
5372806a849cf117596b1f7c8c7d512c519f8092
2 files changed
+33
-8
Documentation/config.txt
+4
@@ -122,6 +122,10 @@ apply.whitespace::
122
branch.<name>.remote::
123
When in branch <name>, it tells `git fetch` which remote to fetch.
124
125
+branch.<name>.merge::
126
+ When in branch <name>, it tells `git fetch` the default remote branch
127
+ to be merged.
128
+
129
pager.color::
130
A boolean to enable/disable colored output when the pager is in
131
use (default is true).
git-parse-remote.sh
+29
-8
@@ -92,9 +92,22 @@ get_remote_default_refs_for_push () {
92
93
# Subroutine to canonicalize remote:local notation.
94
canon_refs_list_for_fetch () {
95
- # Leave only the first one alone; add prefix . to the rest
95
+ # If called from get_remote_default_refs_for_fetch
96
+ # leave the branches in branch.${curr_branch}.merge alone,
97
+ # or the first one otherwise; add prefix . to the rest
98
# to prevent the secondary branches to be merged by default.
97
- dot_prefix=
99
+ merge_branches=
100
+ if test "$1" = "-d"
101
+ then
102
+ shift ; remote="$1" ; shift
103
+ if test "$remote" = "$(get_default_remote)"
104
+ then
105
+ curr_branch=$(git-symbolic-ref HEAD | \
106
+ sed -e 's|^refs/heads/||')
107
+ merge_branches=$(git-repo-config \
108
+ --get-all "branch.${curr_branch}.merge")
109
+ fi
110
+ fi
111
for ref
112
do
113
force=
@@ -107,6 +120,18 @@ canon_refs_list_for_fetch () {
120
expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:"
121
remote=$(expr "z$ref" : 'z\([^:]*\):')
122
local=$(expr "z$ref" : 'z[^:]*:\(.*\)')
123
+ dot_prefix=.
124
+ if test -z "$merge_branches"
125
+ then
126
+ merge_branches=$remote
127
+ dot_prefix=
128
+ else
129
+ for merge_branch in $merge_branches
130
+ do
131
+ [ "$remote" = "$merge_branch" ] &&
132
+ dot_prefix= && break
133
+ done
134
+ fi
135
case "$remote" in
136
'') remote=HEAD ;;
137
refs/heads/* | refs/tags/* | refs/remotes/*) ;;
@@ -126,7 +151,6 @@ canon_refs_list_for_fetch () {
151
die "* refusing to create funny ref '$local_ref_name' locally"
152
fi
153
echo "${dot_prefix}${force}${remote}:${local}"
129
- dot_prefix=.
154
done
155
}
156
@@ -137,7 +161,7 @@ get_remote_default_refs_for_fetch () {
161
'' | config-partial | branches-partial)
162
echo "HEAD:" ;;
163
config)
140
- canon_refs_list_for_fetch \
164
+ canon_refs_list_for_fetch -d "$1" \
165
$(git-repo-config --get-all "remote.$1.fetch") ;;
166
branches)
167
remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
@@ -145,10 +169,7 @@ get_remote_default_refs_for_fetch () {
169
echo "refs/heads/${remote_branch}:refs/heads/$1"
170
;;
171
remotes)
148
- # This prefixes the second and later default refspecs
149
- # with a '.', to signal git-fetch to mark them
150
- # not-for-merge.
151
- canon_refs_list_for_fetch $(sed -ne '/^Pull: */{
172
+ canon_refs_list_for_fetch -d "$1" $(sed -ne '/^Pull: */{
173
s///p
174
}' "$GIT_DIR/remotes/$1")
175
;;