@matheusbsbs / matheus-bagliano / commits / 5a223a0d43
Fork 0

fetch, pull: ask config for remote information

Now you can say [remote.junio] url = git://git.kernel.org/pub/scm/git/git.git pull = next:next in your .git/config. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Apr 30, 2006 at 15:24 UTC 5a223a0d434c874984a0251eca4520ef95718a6d
1 file changed +51 -4
git-parse-remote.sh
+51 -4
@@ -4,13 +4,43 @@
4 # this would fail in that case and would issue an error message.
5 GIT_DIR=$(git-rev-parse --git-dir 2>/dev/null) || :;
6
7 +if [ -d "$GIT_DIR"/remotes -a "$GIT_REWRITE_REMOTES" = true ]; then
8 + echo "Rewriting $GIT_DIR/remotes" >&2
9 + error=0
10 + # rewrite into config
11 + {
12 + cd "$GIT_DIR"/remotes
13 + ls | while read f; do
14 + name=$(echo -n "$f" | tr -c "A-Za-z0-9" ".")
15 + sed -n \
16 + -e "s/^URL: /remote.$name.url . /p" \
17 + -e "s/^Pull: /remote.$name.pull ^$ /p" \
18 + -e "s/^Push: /remote.$name.push ^$ /p" \
19 + < "$f"
20 + done
21 + echo done
22 + } | while read key regex value; do
23 + case $key in
24 + done)
25 + if [ $error = 0 ]; then
26 + mv "$GIT_DIR"/remotes "$GIT_DIR"/remotes.old
27 + fi ;;
28 + *)
29 + git-repo-config $key "$value" $regex || error=1 ;;
30 + esac
31 + done
32 +fi
33 +
34 get_data_source () {
35 case "$1" in
36 */*)
37 # Not so fast. This could be the partial URL shorthand...
38 token=$(expr "z$1" : 'z\([^/]*\)/')
39 remainder=$(expr "z$1" : 'z[^/]*/\(.*\)')
13 - if test -f "$GIT_DIR/branches/$token"
40 + if test "$(git-repo-config --get "remote.$token.url")"
41 + then
42 + echo config-partial
43 + elif test -f "$GIT_DIR/branches/$token"
44 then
45 echo branches-partial
46 else
@@ -18,7 +48,10 @@ get_data_source () {
48 fi
49 ;;
50 *)
21 - if test -f "$GIT_DIR/remotes/$1"
51 + if test "$(git-repo-config --get "remote.$1.url")"
52 + then
53 + echo config
54 + elif test -f "$GIT_DIR/remotes/$1"
55 then
56 echo remotes
57 elif test -f "$GIT_DIR/branches/$1"
@@ -35,6 +68,15 @@ get_remote_url () {
68 case "$data_source" in
69 '')
70 echo "$1" ;;
71 + config-partial)
72 + token=$(expr "z$1" : '\([^/]*\)/')
73 + remainder=$(expr "z$1" : '[^/]*/\(.*\)')
74 + url=$(git-repo-config --get "remote.$token.url")
75 + echo "$url/$remainder"
76 + ;;
77 + config)
78 + git-repo-config --get "remote.$1.url"
79 + ;;
80 remotes)
81 sed -ne '/^URL: */{
82 s///p
@@ -56,8 +98,10 @@ get_remote_url () {
98 get_remote_default_refs_for_push () {
99 data_source=$(get_data_source "$1")
100 case "$data_source" in
59 - '' | branches | branches-partial)
101 + '' | config-partial | branches | branches-partial)
102 ;; # no default push mapping, just send matching refs.
103 + config)
104 + git-repo-config --get-all "remote.$1.push" ;;
105 remotes)
106 sed -ne '/^Push: */{
107 s///p
@@ -111,8 +155,11 @@ canon_refs_list_for_fetch () {
155 get_remote_default_refs_for_fetch () {
156 data_source=$(get_data_source "$1")
157 case "$data_source" in
114 - '' | branches-partial)
158 + '' | config-partial | branches-partial)
159 echo "HEAD:" ;;
160 + config)
161 + canon_refs_list_for_fetch \
162 + $(git-repo-config --get-all "remote.$1.pull") ;;
163 branches)
164 remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1")
165 case "$remote_branch" in '') remote_branch=master ;; esac