Code

Fetch: default remote repository from branch properties
authorSanti Béjar <sbejar@gmail.com>
Sat, 23 Sep 2006 10:05:43 +0000 (12:05 +0200)
committerJunio C Hamano <junkio@cox.net>
Sun, 24 Sep 2006 07:13:49 +0000 (00:13 -0700)
If in branch "foo" and this in config:

[branch "foo"]
       remote=bar

"git fetch" = "git fetch bar"
"git  pull" = "git pull  bar"

Signed-off-by: Santi Béjar <sbejar@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/config.txt
git-fetch.sh
git-parse-remote.sh

index bb2fbc324e6fa93a639b31668a7a030ece7787f0..04c5094fdd4c5e66b186107c0f64d3a82e1e8aa5 100644 (file)
@@ -119,6 +119,9 @@ apply.whitespace::
        Tells `git-apply` how to handle whitespaces, in the same way
        as the '--whitespace' option. See gitlink:git-apply[1].
 
+branch.<name>.remote::
+       When in branch <name>, it tells `git fetch` which remote to fetch.
+
 pager.color::
        A boolean to enable/disable colored output when the pager is in
        use (default is true).
index 09a5d6ceab7875f2344f84d684ea5cc250786c64..50ad101e89500af01edde00b047b91fc16fdcb81 100755 (executable)
@@ -68,11 +68,10 @@ done
 
 case "$#" in
 0)
-       test -f "$GIT_DIR/branches/origin" ||
-               test -f "$GIT_DIR/remotes/origin" ||
-                       git-repo-config --get remote.origin.url >/dev/null ||
-                               die "Where do you want to fetch from today?"
-       set origin ;;
+       origin=$(get_default_remote)
+       test -n "$(get_remote_url ${origin})" ||
+               die "Where do you want to fetch from today?"
+       set x $origin ; shift ;;
 esac
 
 remote_nick="$1"
index 187f0883c9136772677088ddf61228291d4b41d1..69998169b7f2a2a07363a7d1416be129bca82e84 100755 (executable)
@@ -68,6 +68,12 @@ get_remote_url () {
        esac
 }
 
+get_default_remote () {
+       curr_branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
+       origin=$(git-repo-config --get "branch.$curr_branch.remote")
+       echo ${origin:-origin}
+}
+
 get_remote_default_refs_for_push () {
        data_source=$(get_data_source "$1")
        case "$data_source" in