git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] submodule: add --no-fetch parameter to update command
@ 2009-02-05 22:18 Fabian Franz
  2009-02-06 18:01 ` Lars Hjemli
  2009-02-07  8:44 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Fabian Franz @ 2009-02-05 22:18 UTC (permalink / raw)
  To: git; +Cc: hjemli, Fabian Franz

git submodule update --no-fetch makes it possible to use git submodule
update in complete offline mode by not fetching new revisions.

This does make sense in the following setup:

* There is an unstable and a stable branch in the super/master repository.
* The submodules might be at different revisions in the branches.
* You are at some place without internet connection ;)

With this patch it is now possible to change branches and update
the submodules to be at the recorded revision without online access.

Another advantage is that with -N the update operation is faster, because fetch is checking for new updates even if there was no fetch/pull on the super/master repository since the last update.

Signed-off-by: Fabian Franz <git@fabian-franz.de>
---
 Documentation/git-submodule.txt |    7 ++++++-
 git-submodule.sh                |   19 ++++++++++++++++---
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 2f207fb..3b8df44 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -12,7 +12,7 @@ SYNOPSIS
 'git submodule' [--quiet] add [-b branch] [--] <repository> <path>
 'git submodule' [--quiet] status [--cached] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
-'git submodule' [--quiet] update [--init] [--] [<path>...]
+'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...]
 'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
 'git submodule' [--quiet] foreach <command>
 'git submodule' [--quiet] sync [--] [<path>...]
@@ -172,6 +172,11 @@ OPTIONS
 	(the default). This limit only applies to modified submodules. The
 	size is always limited to 1 for added/deleted/typechanged submodules.
 
+-N::
+--no-fetch::
+	This option is only valid for the update command.
+	Don't fetch new objects from the remote site.
+
 <path>...::
 	Paths to submodule(s). When specified this will restrict the command
 	to only operate on the submodules found at the specified paths.
diff --git a/git-submodule.sh b/git-submodule.sh
index 2f47e06..af8d10c 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -5,7 +5,7 @@
 # Copyright (c) 2007 Lars Hjemli
 
 USAGE="[--quiet] [--cached] \
-[add <repo> [-b branch] <path>]|[status|init|update [-i|--init]|summary [-n|--summary-limit <n>] [<commit>]] \
+[add <repo> [-b branch] <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \
 [--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
 OPTIONS_SPEC=
 . git-sh-setup
@@ -16,6 +16,7 @@ command=
 branch=
 quiet=
 cached=
+nofetch=
 
 #
 # print stuff on stdout unless -q was specified
@@ -300,6 +301,10 @@ cmd_update()
 			shift
 			cmd_init "$@" || return
 			;;
+		-N|--no-fetch)
+			shift
+			nofetch=1
+			;;
 		--)
 			shift
 			break
@@ -345,8 +350,16 @@ cmd_update()
 			then
 				force="-f"
 			fi
-			(unset GIT_DIR; cd "$path" && git-fetch &&
-				git-checkout $force -q "$sha1") ||
+
+			if test -z "$nofetch"
+			then
+				(unset GIT_DIR; cd "$path" &&
+					git-fetch) ||
+				die "Unable to fetch in submodule path '$path'"
+			fi
+
+			(unset GIT_DIR; cd "$path" &&
+				  git-checkout $force -q "$sha1") ||
 			die "Unable to checkout '$sha1' in submodule path '$path'"
 
 			say "Submodule path '$path': checked out '$sha1'"
-- 
1.6.1.2.351.gccea

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] submodule: add --no-fetch parameter to update command
  2009-02-05 22:18 [PATCH] submodule: add --no-fetch parameter to update command Fabian Franz
@ 2009-02-06 18:01 ` Lars Hjemli
  2009-02-07 15:44   ` Fabian Franz
  2009-02-07  8:44 ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Lars Hjemli @ 2009-02-06 18:01 UTC (permalink / raw)
  To: Fabian Franz; +Cc: git

On Thu, Feb 5, 2009 at 23:18, Fabian Franz <git@fabian-franz.de> wrote:
> git submodule update --no-fetch makes it possible to use git submodule
> update in complete offline mode by not fetching new revisions.

This is nice, but it would be even nicer IMHO if "submodule update"
first tried to checkout the submodule commit and only if that failed
would it try to fetch objects (before re-trying the checkout).


>  Documentation/git-submodule.txt |    7 ++++++-
>  git-submodule.sh                |   19 ++++++++++++++++---
>  2 files changed, 22 insertions(+), 4 deletions(-)

Extending t/t7400-submodule-basic.sh would also be nice (either for
--no-fetch or for a less fetchy "submodule update").

--
larsh

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] submodule: add --no-fetch parameter to update command
  2009-02-05 22:18 [PATCH] submodule: add --no-fetch parameter to update command Fabian Franz
  2009-02-06 18:01 ` Lars Hjemli
@ 2009-02-07  8:44 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2009-02-07  8:44 UTC (permalink / raw)
  To: Fabian Franz; +Cc: git, hjemli

Fabian Franz <git@fabian-franz.de> writes:

> git submodule update --no-fetch makes it possible to use git submodule
> update in complete offline mode by not fetching new revisions.
>
> This does make sense in the following setup:
>
> * There is an unstable and a stable branch in the super/master repository.
> * The submodules might be at different revisions in the branches.
> * You are at some place without internet connection ;)
>
> With this patch it is now possible to change branches and update
> the submodules to be at the recorded revision without online access.

How is this better than "cd submodule/path && git checkout whatever"?

> Another advantage is that with -N the update operation is faster,
> because fetch is checking for new updates even if there was no
> fetch/pull on the super/master repository since the last update.

Do we know this is common enough to deserve a shortopt -N?

The logic of the patch itself looks sane to me.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] submodule: add --no-fetch parameter to update command
  2009-02-06 18:01 ` Lars Hjemli
@ 2009-02-07 15:44   ` Fabian Franz
  0 siblings, 0 replies; 4+ messages in thread
From: Fabian Franz @ 2009-02-07 15:44 UTC (permalink / raw)
  To: git

> Fabian Franz <git@fabian-franz.de> writes:
> 
> > git submodule update --no-fetch makes it possible to use git submodule
> > update in complete offline mode by not fetching new revisions.
> >
> > This does make sense in the following setup:
> >
> > * There is an unstable and a stable branch in the super/master
> repository.
> > * The submodules might be at different revisions in the branches.
> > * You are at some place without internet connection ;)
> >
> > With this patch it is now possible to change branches and update
> > the submodules to be at the recorded revision without online access.
> 
> How is this better than "cd submodule/path && git checkout whatever"?

It is better if you have a complex setup recorded in the master repository.

If my co-worker commited his newest revisions for the "stable" branch, I
might not know which of his revisions I need to checkout.

> > Another advantage is that with -N the update operation is faster,
> > because fetch is checking for new updates even if there was no
> > fetch/pull on the super/master repository since the last update.
> 
> Do we know this is common enough to deserve a shortopt -N?

I don't think so, gonna resend later.

> The logic of the patch itself looks sane to me.

Nice.

Best Wishes,

Fabian

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-02-07 15:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-05 22:18 [PATCH] submodule: add --no-fetch parameter to update command Fabian Franz
2009-02-06 18:01 ` Lars Hjemli
2009-02-07 15:44   ` Fabian Franz
2009-02-07  8:44 ` Junio C Hamano

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).