git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Santi Béjar" <sbejar@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Subject: [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag.
Date: Mon, 16 Oct 2006 15:40:42 +0200	[thread overview]
Message-ID: <87ac3w8jl1.fsf@gmail.com> (raw)


It allows to separate when you fetch from when you merge. So, a "git pull"
can be:

$ git fetch
$ git pull --local

and the pull call can be made later. This is usefull when you have multiple
branches and you want to merge the same "upstream" branch, or when you are
offline but you have already fetched the remote branch.

Note that this is different from:

$ git fetch
$ git pull . origin

(1) you do not have to tell explicitly the branch to merge
(2) the commit message is exactly as with "git pull"

Signed-off-by: Santi Béjar <sbejar@gmail.com>
---
 Documentation/fetch-options.txt |    3 +++
 git-fetch.sh                    |   25 +++++++++++++++++++------
 git-parse-remote.sh             |   22 ++++++++++++++++++++++
 3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 13f34d3..3a6cb3d 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -39,3 +39,6 @@
 	check.  Note that fetching into the current branch will not
 	update the index and working directory, so use it with care.
 
+\--local::
+	Do not fetch from the remote repository. Use the already fetched
+	branches to program the merge for `git-pull`.
diff --git a/git-fetch.sh b/git-fetch.sh
index 79222fb..5ff800a 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -21,6 +21,7 @@ update_head_ok=
 exec=
 upload_pack=
 keep=--thin
+local_fetch=
 while case "$#" in 0) break ;; esac
 do
 	case "$1" in
@@ -56,6 +57,9 @@ do
 	--reflog-action=*)
 		rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
 		;;
+	--local)
+		local_fetch=t
+		;;
 	-*)
 		usage
 		;;
@@ -80,6 +84,10 @@ refs=
 rref=
 rsync_slurped_objects=
 
+[ "$local_fetch" = t ] && [ "$remote_nick" = "$remote" ] && \
+    [ "$remote" != "." ] && \
+    die "Flag --local only compatible with remote shorthands"
+
 rloga="$rloga $remote_nick"
 test "$remote_nick" = "$remote" || rloga="$rloga $remote"
 
@@ -285,8 +293,8 @@ fetch_main () {
       rref="$rref$LF$remote_name"
 
       # There are transports that can fetch only one head at a time...
-      case "$remote" in
-      http://* | https://* | ftp://*)
+      case "$local_fetch,$remote" in
+      ,http://* | ,https://* | ,ftp://*)
 	  if [ -n "$GIT_SSL_NO_VERIFY" ]; then
 	      curl_extra_args="-k"
 	  fi
@@ -313,7 +321,7 @@ fetch_main () {
 	  echo >&2 Fetching "$remote_name from $remote" using http
 	  git-http-fetch -v -a "$head" "$remote/" || exit
 	  ;;
-      rsync://*)
+      ,rsync://*)
 	  TMP_HEAD="$GIT_DIR/TMP_HEAD"
 	  rsync -L -q "$remote/$remote_name" "$TMP_HEAD" || exit 1
 	  head=$(git-rev-parse --verify TMP_HEAD)
@@ -343,6 +351,11 @@ fetch_main () {
 	      rsync_slurped_objects=t
 	  }
 	  ;;
+      t,*)
+	  [ -z "$local_name" ] &&\
+		local_name=$(get_ref_for_remote_branch "$remote_nick" "$remote_name")
+	  head=$(git-rev-parse --verify $local_name^0) || exit
+	  ;;
       *)
 	  # We will do git native transport with just one call later.
 	  continue ;;
@@ -353,8 +366,8 @@ fetch_main () {
 
   done
 
-  case "$remote" in
-  http://* | https://* | ftp://* | rsync://* )
+  case "$local_fetch,$remote" in
+  ,http://* | ,https://* | ,ftp://* | ,rsync://* | t,*)
       ;; # we are already done.
   *)
     ( : subshell because we muck with IFS
@@ -406,7 +419,7 @@ fetch_main () {
 fetch_main "$reflist"
 
 # automated tag following
-case "$no_tags$tags" in
+case "$no_tags$tags$local_fetch" in
 '')
 	case "$reflist" in
 	*:refs/*)
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index c325ef7..679f73c 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -236,3 +236,25 @@ resolve_alternates () {
 		esac
 	done
 }
+
+get_ref_for_remote_branch (){
+	data_source=$(get_data_source "$1")
+	case "$data_source" in
+	'' | config-partial | branches | branches-partial)
+		test "$1" = . && echo $2
+		;;
+	config)
+		ref=$(git-repo-config --get-all "remote.$1.fetch" |\
+			grep "^$2:")
+		expr "z$ref" : 'z[^:]*:\(.*\)'
+		;;
+	remotes)
+		ref=$(sed -ne '/^Pull: */{
+				s///p
+			}' "$GIT_DIR/remotes/$1" | grep "$2:")
+		expr "z$ref" : 'z[^:]*:\(.*\)'
+		;;
+	*)
+		die "internal error: get-ref-for-remote-branch $1 $2" ;;
+	esac
+}
-- 
1.4.3.rc2.ga442

             reply	other threads:[~2006-10-16 13:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-16 13:40 Santi Béjar [this message]
2006-10-17  7:14 ` [RFC/PATCH] git-fetch: Use already fetched branch with the --local flag Junio C Hamano
2006-10-17  8:36   ` Santi Béjar
2006-10-17 14:03 ` Santi Béjar

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=87ac3w8jl1.fsf@gmail.com \
    --to=sbejar@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).