All of lore.kernel.org
 help / color / mirror / Atom feed
* Restart submodule update --recursive
@ 2010-10-28  7:25 Lukasz Palczewski
  2010-10-28 10:35 ` Johan Herland
  2010-10-28 18:15 ` Jonathan Nieder
  0 siblings, 2 replies; 11+ messages in thread
From: Lukasz Palczewski @ 2010-10-28  7:25 UTC (permalink / raw)
  To: git

Hi.
I have a problem with the time and the stoping of the submodule update command
when the error occures.
In our project we have lots of submodules with submodules in them. So I use git
command: git submodule update --recursive, to update all the submodules, but it
take some time to do it. I have to do it quite often becouse I'm a tester of the
software and I usually don't know which submodule I need to update, to have the
newest version. If I have some local changes in some submodule, the command
stops and I have to revert the changes and start the submodule update from the
begining again. 
Is there a way to start the submodule update from the place, where the error
occured and the command stop? Something like:
git submodule update --recursive --restart_form_last_error
If there isn't, can You add this feature?

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

* Re: Restart submodule update --recursive
  2010-10-28  7:25 Restart submodule update --recursive Lukasz Palczewski
@ 2010-10-28 10:35 ` Johan Herland
  2010-10-29  7:28   ` Lukasz Palczewski
  2010-10-28 18:15 ` Jonathan Nieder
  1 sibling, 1 reply; 11+ messages in thread
From: Johan Herland @ 2010-10-28 10:35 UTC (permalink / raw)
  To: Lukasz Palczewski; +Cc: git

On Thursday 28 October 2010, Lukasz Palczewski wrote:
> Hi.
> I have a problem with the time and the stoping of the submodule
> update command when the error occures.
> In our project we have lots of submodules with submodules in them. So
> I use git command: git submodule update --recursive, to update all
> the submodules, but it take some time to do it. I have to do it quite
> often becouse I'm a tester of the software and I usually don't know
> which submodule I need to update, to have the newest version. If I
> have some local changes in some submodule, the command stops and I
> have to revert the changes and start the submodule update from the
> begining again.
> Is there a way to start the submodule update from the place, where
> the error occured and the command stop? Something like:
> git submodule update --recursive --restart_form_last_error

No, but you can use 'git submodule foreach --recursive "$SCRIPT"', where 
$SCRIPT is a command (or list of commands) for updating your current 
submodule. As long as the SCRIPT returns successfully (exit value 0), 
the submodule foreach will keep going into each submodule. You can the 
look at the output from your script to deduce which submodules need to 
be updated manually. Or you may even be able to solve your problem 
automatically.

You could for example try something like (all on one line):

git submodule foreach --recursive "git fetch && git stash && git 
checkout $sha1 && git stash pop; true"


...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net

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

* Re: Restart submodule update --recursive
  2010-10-28  7:25 Restart submodule update --recursive Lukasz Palczewski
  2010-10-28 10:35 ` Johan Herland
@ 2010-10-28 18:15 ` Jonathan Nieder
  2010-10-29  7:17   ` Lukasz Palczewski
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Nieder @ 2010-10-28 18:15 UTC (permalink / raw)
  To: Lukasz Palczewski; +Cc: git, Jens Lehmann

(+cc: Jens of submodule-usability-enhancements fame)

Hi Lukasz,

Lukasz Palczewski wrote:

>                                                                       I use git
> command: git submodule update --recursive
[...]
>                 If I have some local changes in some submodule, the command
> stops and I have to revert the changes and start the submodule update from the
> begining again.
> Is there a way to start the submodule update from the place, where the error
> occured and the command stop? Something like:
> git submodule update --recursive --restart_form_last_error

How many submodules are involved here?  I suspect there is some
optimization possible: if a submodule was already updated, there
should not be much to do on the second pass, right?  What aspect of
the update seems to take the most time (as witnessed by pstree -a, for
example)?  Maybe what would be most useful is a hypothetical

	git submodule update --fetch-only
	(or git fetch --recursive)

followed by

	git submodule update --no-fetch
	(or git checkout --recursive)

?

But if there are many, many submodules, it could be better to script
a --save-progress and --resume along the lines you described.

Two possible approaches:

 - Make a new script using "git submodule foreach --recursive" that
   steps through the list by hand, or

 - Take cmd_update from git-submodule.sh in the git sources and modify
   to taste.

If you follow either of those approaches, please keep up posted.  Such
scripts are inspiring and can be useful to others, too.

Thanks for an interesting example,
Jonathan

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

* Re: Restart submodule update --recursive
  2010-10-28 18:15 ` Jonathan Nieder
@ 2010-10-29  7:17   ` Lukasz Palczewski
  2010-10-29  9:12     ` Jonathan Nieder
  0 siblings, 1 reply; 11+ messages in thread
From: Lukasz Palczewski @ 2010-10-29  7:17 UTC (permalink / raw)
  To: git

Hi Jonathan,

Jonathan Nieder writes:

> [...]
> But if there are many, many submodules, it could be better to script
> a --save-progress and --resume along the lines you described.
> 
> Two possible approaches:
> 
>  - Make a new script using "git submodule foreach --recursive" that
>    steps through the list by hand, or
> 
>  - Take cmd_update from git-submodule.sh in the git sources and modify
>    to taste.
> [...]

I think modyfying the git-submodule.sh will be better for me. So I looked into
it and first problem araised: 
How do I get a name of submodule with a name of a previous submodule?
Maybe I will start with how my repository looks like:

Main
 |
 --> sub1
 |     |
 |     --> nsub1
 |     |
 |     --> nsub2
 |     |
 |     --> nsub3
 |     |
 |     --> etc.     
 |
 --> sub2
 |     |
 |     --> nsub2 (no nsub1)
 |     |
 |     --> nsub3
 |     |
 |     --> nsub4
 |
 --> sub3
 |     |
 |     --> nsub1
 |     |
 |     --> nsub3 (no nsub2)
 |     |
 |     --> nsub4
 |
 etc.

It would be nice if I could get name like this sub1/nsub1 when I am in submodule
sub1. Right now, I can get submodule name: nsub1. I tried to find some commands
to get something like this, but could not find it.

If I can get that, I will be in home. Do You know how to do it?
BTW. thanks for previous suggestion.

Lukasz Palczewski

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

* Re: Restart submodule update --recursive
  2010-10-28 10:35 ` Johan Herland
@ 2010-10-29  7:28   ` Lukasz Palczewski
  0 siblings, 0 replies; 11+ messages in thread
From: Lukasz Palczewski @ 2010-10-29  7:28 UTC (permalink / raw)
  To: git

Hi Johan,

Johan Herland writes:

> [...]
> You could for example try something like (all on one line):
> 
> git submodule foreach --recursive "git fetch && git stash && git 
> checkout $sha1 && git stash pop; true"
> 
> ...Johan
> 

Thanks for the suggestion. Using s script in a command good idea, but it will
work only for the local changes (I think), so I am continuing with a second
suggestion from Jonathan. If it works, it would not matter what error arises.

Lukasz Palczewski

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

* Re: Restart submodule update --recursive
  2010-10-29  7:17   ` Lukasz Palczewski
@ 2010-10-29  9:12     ` Jonathan Nieder
  2010-10-29 11:37       ` Lukasz Palczewski
  0 siblings, 1 reply; 11+ messages in thread
From: Jonathan Nieder @ 2010-10-29  9:12 UTC (permalink / raw)
  To: Lukasz Palczewski; +Cc: git, Johan Herland, Jens Lehmann

Hi Lukasz,

[side note: if you use a newsreader, please reply by mail instead of
through gmane so the Cc: list can be preserved.]

Lukasz Palczewski wrote:

> I think modyfying the git-submodule.sh will be better for me. So I looked into
> it and first problem araised: 
> How do I get a name of submodule with a name of a previous submodule?
[...]
> It would be nice if I could get name like this sub1/nsub1 when I am in submodule
> sub1.

What path do you want to get when there are three levels of submodules?

To understand how git-submodule works, it helps to see how low-level it
is.  The core is this function:

 #
 # Get submodule info for registered submodules
 # $@ = path to limit submodule list
 #
 module_list ()
 {
	git ls-files --error-unmatch --stage -- "$@" | grep '^160000 '
 }

which is just reading submodule entries from the index in the current
repository.  Like all index entries, they are attached to paths relative to
the toplevel of the current repository.

To get a path relative to the toplevel of the superproject using module_list,
you need to build it up as you go along.  For example,

	git submodule foreach --recursive 'echo $prefix'

does this (see cmd_foreach).
---
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 1ed331c..e9bdbca 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -145,17 +145,21 @@ summary::
 
 foreach::
 	Evaluates an arbitrary shell command in each checked out submodule.
-	The command has access to the variables $name, $path, $sha1 and
-	$toplevel:
+	The command has access to the variables $name, $path, $prefix, $sha1,
+	and $toplevel:
 	$name is the name of the relevant submodule section in .gitmodules,
 	$path is the name of the submodule directory relative to the
 	superproject, $sha1 is the commit as recorded in the superproject,
-	and $toplevel is the absolute path to the top-level of the superproject.
+	$toplevel is the absolute path to the top-level of the superproject,
+	and $toplevel/${prefix}$path is the absolute path for any file
+	in the submodule worktree.
 	Any submodules defined in the superproject but not checked out are
 	ignored by this command. Unless given --quiet, foreach prints the name
 	of each submodule before evaluating the command.
 	If --recursive is given, submodules are traversed recursively (i.e.
-	the given shell command is evaluated in nested submodules as well).
+	the given shell command is evaluated in nested submodules as well)
+	and the superproject used to define $toplevel and $prefix is the
+	outermost project.
 	A non-zero return from the command in any submodule causes
 	the processing to terminate. This can be overridden by adding '|| :'
 	to the end of the command.
-- 

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

* Re: Restart submodule update --recursive
  2010-10-29  9:12     ` Jonathan Nieder
@ 2010-10-29 11:37       ` Lukasz Palczewski
  2010-10-29 16:40         ` Jonathan Nieder
  2010-10-30  7:17         ` Jens Lehmann
  0 siblings, 2 replies; 11+ messages in thread
From: Lukasz Palczewski @ 2010-10-29 11:37 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, Johan Herland, Jens Lehmann, Piotrek Pientka

[-- Attachment #1: Type: text/plain, Size: 973 bytes --]

Jonathan Nieder wrote:
> Hi Lukasz,
>
> [side note: if you use a newsreader, please reply by mail instead of
> through gmane so the Cc: list can be preserved.]
Sorry, but I do not use it. I will send You a normal email.

I have added two options to git submodule update:
--save-progress
--resume-update
First one You can use, to save the ./.git/SubmoduleUpdateLog.log the 
progress of updating:
git submodule update --recursive --save-progress
The second one is used for skipping updated submodules:
git submodule update --recursive --resume-update

The downside of it is, that u can use only one --resume-update. If there 
will be another error, then using it again will start form the last 
submodule that --save-progres saved.

I have send two files:
"git-submodule" - it has my changes
"git-submodule - Original" - it not modyfied
so that You can see what lines I have added.

Let me know if this change will be in next version of git.

Best regards,
Lukasz Palczewski

[-- Attachment #2: git-submodule --]
[-- Type: text/plain, Size: 19175 bytes --]

#!/bin/sh
#
# git-submodules.sh: add, init, update or list git submodules
#
# Copyright (c) 2007 Lars Hjemli

dashless=$(basename "$0" | sed -e 's/-/ /')
USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
   or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
   or: $dashless [--quiet] init [--] [<path>...]
   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
   or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
   or: $dashless [--quiet] foreach [--recursive] <command>
   or: $dashless [--quiet] sync [--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
. git-parse-remote
require_work_tree

command=
branch=
force=
reference=
cached=
recursive=
init=
files=
nofetch=
update=
prefix=

# Resolve relative url by appending to parent's url
resolve_relative_url ()
{
	remote=$(get_default_remote)
	remoteurl=$(git config "remote.$remote.url") ||
		die "remote ($remote) does not have a url defined in .git/config"
	url="$1"
	remoteurl=${remoteurl%/}
	while test -n "$url"
	do
		case "$url" in
		../*)
			url="${url#../}"
			remoteurl="${remoteurl%/*}"
			;;
		./*)
			url="${url#./}"
			;;
		*)
			break;;
		esac
	done
	echo "$remoteurl/${url%/}"
}

#
# Get submodule info for registered submodules
# $@ = path to limit submodule list
#
module_list()
{
	git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
}

#
# Map submodule path to submodule name
#
# $1 = path
#
module_name()
{
	# Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
	re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
	name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
		sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
       test -z "$name" &&
       die "No submodule mapping found in .gitmodules for path '$path'"
       echo "$name"
}

#
# Clone a submodule
#
# Prior to calling, cmd_update checks that a possibly existing
# path is not a git repository.
# Likewise, cmd_add checks that path does not exist at all,
# since it is the location of a new submodule.
#
module_clone()
{
	path=$1
	url=$2
	reference="$3"

	# If there already is a directory at the submodule path,
	# expect it to be empty (since that is the default checkout
	# action) and try to remove it.
	# Note: if $path is a symlink to a directory the test will
	# succeed but the rmdir will fail. We might want to fix this.
	if test -d "$path"
	then
		rmdir "$path" 2>/dev/null ||
		die "Directory '$path' exists, but is neither empty nor a git repository"
	fi

	test -e "$path" &&
	die "A file already exist at path '$path'"

	if test -n "$reference"
	then
		git-clone "$reference" -n "$url" "$path"
	else
		git-clone -n "$url" "$path"
	fi ||
	die "Clone of '$url' into submodule path '$path' failed"
}

#
# Add a new submodule to the working tree, .gitmodules and the index
#
# $@ = repo path
#
# optional branch is stored in global branch variable
#
cmd_add()
{
	# parse $args after "submodule ... add".
	while test $# -ne 0
	do
		case "$1" in
		-b | --branch)
			case "$2" in '') usage ;; esac
			branch=$2
			shift
			;;
		-f | --force)
			force=$1
			;;
		-q|--quiet)
			GIT_QUIET=1
			;;
		--reference)
			case "$2" in '') usage ;; esac
			reference="--reference=$2"
			shift
			;;
		--reference=*)
			reference="$1"
			shift
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	repo=$1
	path=$2

	if test -z "$path"; then
		path=$(echo "$repo" |
			sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
	fi

	if test -z "$repo" -o -z "$path"; then
		usage
	fi

	# assure repo is absolute or relative to parent
	case "$repo" in
	./*|../*)
		# dereference source url relative to parent's url
		realrepo=$(resolve_relative_url "$repo") || exit
		;;
	*:*|/*)
		# absolute url
		realrepo=$repo
		;;
	*)
		die "repo URL: '$repo' must be absolute or begin with ./|../"
	;;
	esac

	# normalize path:
	# multiple //; leading ./; /./; /../; trailing /
	path=$(printf '%s/\n' "$path" |
		sed -e '
			s|//*|/|g
			s|^\(\./\)*||
			s|/\./|/|g
			:start
			s|\([^/]*\)/\.\./||
			tstart
			s|/*$||
		')
	git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
	die "'$path' already exists in the index"

	if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
	then
		echo >&2 "The following path is ignored by one of your .gitignore files:" &&
		echo >&2 $path &&
		echo >&2 "Use -f if you really want to add it."
		exit 1
	fi

	# perhaps the path exists and is already a git repo, else clone it
	if test -e "$path"
	then
		if test -d "$path"/.git -o -f "$path"/.git
		then
			echo "Adding existing repo at '$path' to the index"
		else
			die "'$path' already exists and is not a valid git repo"
		fi

		case "$repo" in
		./*|../*)
			url=$(resolve_relative_url "$repo") || exit
		    ;;
		*)
			url="$repo"
			;;
		esac
		git config submodule."$path".url "$url"
	else

		module_clone "$path" "$realrepo" "$reference" || exit
		(
			clear_local_git_env
			cd "$path" &&
			# ash fails to wordsplit ${branch:+-b "$branch"...}
			case "$branch" in
			'') git checkout -f -q ;;
			?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
			esac
		) || die "Unable to checkout submodule '$path'"
	fi

	git add $force "$path" ||
	die "Failed to add submodule '$path'"

	git config -f .gitmodules submodule."$path".path "$path" &&
	git config -f .gitmodules submodule."$path".url "$repo" &&
	git add --force .gitmodules ||
	die "Failed to register submodule '$path'"
}

#
# Execute an arbitrary command sequence in each checked out
# submodule
#
# $@ = command to execute
#
cmd_foreach()
{
	# parse $args after "submodule ... foreach".
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			;;
		--recursive)
			recursive=1
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	toplevel=$(pwd)

	module_list |
	while read mode sha1 stage path
	do
		if test -e "$path"/.git
		then
			say "Entering '$prefix$path'"
			name=$(module_name "$path")
			(
				prefix="$prefix$path/"
				clear_local_git_env
				cd "$path" &&
				eval "$@" &&
				if test -n "$recursive"
				then
					cmd_foreach "--recursive" "$@"
				fi
			) ||
			die "Stopping at '$path'; script returned non-zero status."
		fi
	done
}

#
# Register submodules in .git/config
#
# $@ = requested paths (default to all)
#
cmd_init()
{
	# parse $args after "submodule ... init".
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	module_list "$@" |
	while read mode sha1 stage path
	do
		# Skip already registered paths
		name=$(module_name "$path") || exit
		url=$(git config submodule."$name".url)
		test -z "$url" || continue

		url=$(git config -f .gitmodules submodule."$name".url)
		test -z "$url" &&
		die "No url found for submodule path '$path' in .gitmodules"

		# Possibly a url relative to parent
		case "$url" in
		./*|../*)
			url=$(resolve_relative_url "$url") || exit
			;;
		esac

		git config submodule."$name".url "$url" ||
		die "Failed to register url for submodule path '$path'"

		upd="$(git config -f .gitmodules submodule."$name".update)"
		test -z "$upd" ||
		git config submodule."$name".update "$upd" ||
		die "Failed to register update mode for submodule path '$path'"

		say "Submodule '$name' ($url) registered for path '$path'"
	done
}

#
# Update each submodule path to correct revision, using clone and checkout as needed
#
# $@ = requested paths (default to all)
#
cmd_update()
{
	# parse $args after "submodule ... update".
	orig_args="$@"
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			shift
			GIT_QUIET=1
			;;
		-i|--init)
			init=1
			shift
			;;
		-N|--no-fetch)
			shift
			nofetch=1
			;;
		-r|--rebase)
			shift
			update="rebase"
			;;
		--reference)
			case "$2" in '') usage ;; esac
			reference="--reference=$2"
			shift 2
			;;
		--reference=*)
			reference="$1"
			shift
			;;
		-m|--merge)
			shift
			update="merge"
			;;
		--recursive)
			shift
			recursive=1
			;;
		--save-progress)
			shift
			save_progress=1
			if test -e ./.git/SubmoduleUpdateLog.log
			then
				rm ./.git/SubmoduleUpdateLog.log
			fi
			;;	
		--resume-update)
			shift
			submodule_resume=1
			;;				
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
	done

	if test -n "$init"
	then
		cmd_init "--" "$@" || return
	fi
		
	module_list "$@" |
	while read mode sha1 stage path
	do		
		name=$(module_name "$path") || exit
		url=$(git config submodule."$name".url)
		update_module=$(git config submodule."$name".update)
		
		if test -n "$submodule_resume"
		then
			SubmodulePathResume=`pwd`
			SubmodulePathResume=$SubmodulePathResume/"$name"
			
			#say $SubmodulePathResume
			if test -e ./.git/SubmoduleUpdateLog.log
			then
				AFile=`cat "./.git/SubmoduleUpdateLog.log" | grep "$SubmodulePathResume"`
				
				#say $AFile;			
				if test -n "$AFile"
				then
					say "Skip module '$SubmodulePathResume'"
					CancelRecursive=1
				else
					#say "Checking"
					#say "$SubmodulePathResume"
					CancelRecursive=""
				fi			
			fi
		fi
		
		if test -z "$url"
		then
			# Only mention uninitialized submodules when its
			# path have been specified
			test "$#" != "0" &&
			say "Submodule path '$path' not initialized" &&
			say "Maybe you want to use 'update --init'?"
			continue
		fi

		if ! test -d "$path"/.git -o -f "$path"/.git
		then
			module_clone "$path" "$url" "$reference"|| exit
			subsha1=
		else
			subsha1=$(clear_local_git_env; cd "$path" &&
				git rev-parse --verify HEAD) ||
			die "Unable to find current revision in submodule path '$path'"
		fi

		if ! test -z "$update"
		then
			update_module=$update
		fi

		if test "$subsha1" != "$sha1"
		then
			force=
			if test -z "$subsha1"
			then
				force="-f"
			fi

			if test -z "$nofetch"
			then
				(clear_local_git_env; cd "$path" &&
					git-fetch) ||
				die "Unable to fetch in submodule path '$path'"
			fi
			
			case "$update_module" in
			rebase)
				command="git rebase"
				action="rebase"
				msg="rebased onto"
				;;
			merge)
				command="git merge"
				action="merge"
				msg="merged in"
				;;
			*)
				command="git checkout $force -q"
				action="checkout"
				msg="checked out"
				;;
			esac

			(clear_local_git_env; cd "$path" && $command "$sha1") ||
			die "Unable to $action '$sha1' in submodule path '$path'"
			say "Submodule path '$path': $msg '$sha1'"
		fi
	
		if test -n "$recursive"
		then
			if test -z "$CancelRecursive"
			then
				(clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
				die "Failed to recurse into submodule path '$path'"
			fi
		fi
		
		if test -n "$save_progress"
		then
				SubmodulePath=`pwd`
				SubmodulePath=$SubmodulePath/"$name"
				
				#say "'$SubmodulePath'"
				echo "'$SubmodulePath'" >> ./.git/SubmoduleUpdateLog.log
		fi
	done
}

set_name_rev () {
	revname=$( (
		clear_local_git_env
		cd "$1" && {
			git describe "$2" 2>/dev/null ||
			git describe --tags "$2" 2>/dev/null ||
			git describe --contains "$2" 2>/dev/null ||
			git describe --all --always "$2"
		}
	) )
	test -z "$revname" || revname=" ($revname)"
}
#
# Show commit summary for submodules in index or working tree
#
# If '--cached' is given, show summary between index and given commit,
# or between working tree and given commit
#
# $@ = [commit (default 'HEAD'),] requested paths (default all)
#
cmd_summary() {
	summary_limit=-1
	for_status=
	diff_cmd=diff-index

	# parse $args after "submodule ... summary".
	while test $# -ne 0
	do
		case "$1" in
		--cached)
			cached="$1"
			;;
		--files)
			files="$1"
			;;
		--for-status)
			for_status="$1"
			;;
		-n|--summary-limit)
			if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
			then
				:
			else
				usage
			fi
			shift
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	test $summary_limit = 0 && return

	if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
	then
		head=$rev
		test $# = 0 || shift
	elif test -z "$1" -o "$1" = "HEAD"
	then
		# before the first commit: compare with an empty tree
		head=$(git hash-object -w -t tree --stdin </dev/null)
		test -z "$1" || shift
	else
		head="HEAD"
	fi

	if [ -n "$files" ]
	then
		test -n "$cached" &&
		die "--cached cannot be used with --files"
		diff_cmd=diff-files
		head=
	fi

	cd_to_toplevel
	# Get modified modules cared by user
	modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
		sane_egrep '^:([0-7]* )?160000' |
		while read mod_src mod_dst sha1_src sha1_dst status name
		do
			# Always show modules deleted or type-changed (blob<->module)
			test $status = D -o $status = T && echo "$name" && continue
			# Also show added or modified modules which are checked out
			GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
			echo "$name"
		done
	)

	test -z "$modules" && return

	git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
	sane_egrep '^:([0-7]* )?160000' |
	cut -c2- |
	while read mod_src mod_dst sha1_src sha1_dst status name
	do
		if test -z "$cached" &&
			test $sha1_dst = 0000000000000000000000000000000000000000
		then
			case "$mod_dst" in
			160000)
				sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
				;;
			100644 | 100755 | 120000)
				sha1_dst=$(git hash-object $name)
				;;
			000000)
				;; # removed
			*)
				# unexpected type
				echo >&2 "unexpected mode $mod_dst"
				continue ;;
			esac
		fi
		missing_src=
		missing_dst=

		test $mod_src = 160000 &&
		! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
		missing_src=t

		test $mod_dst = 160000 &&
		! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
		missing_dst=t

		total_commits=
		case "$missing_src,$missing_dst" in
		t,)
			errmsg="  Warn: $name doesn't contain commit $sha1_src"
			;;
		,t)
			errmsg="  Warn: $name doesn't contain commit $sha1_dst"
			;;
		t,t)
			errmsg="  Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
			;;
		*)
			errmsg=
			total_commits=$(
			if test $mod_src = 160000 -a $mod_dst = 160000
			then
				range="$sha1_src...$sha1_dst"
			elif test $mod_src = 160000
			then
				range=$sha1_src
			else
				range=$sha1_dst
			fi
			GIT_DIR="$name/.git" \
			git rev-list --first-parent $range -- | wc -l
			)
			total_commits=" ($(($total_commits + 0)))"
			;;
		esac

		sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
		sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
		if test $status = T
		then
			if test $mod_dst = 160000
			then
				echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
			else
				echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
			fi
		else
			echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
		fi
		if test -n "$errmsg"
		then
			# Don't give error msg for modification whose dst is not submodule
			# i.e. deleted or changed to blob
			test $mod_dst = 160000 && echo "$errmsg"
		else
			if test $mod_src = 160000 -a $mod_dst = 160000
			then
				limit=
				test $summary_limit -gt 0 && limit="-$summary_limit"
				GIT_DIR="$name/.git" \
				git log $limit --pretty='format:  %m %s' \
				--first-parent $sha1_src...$sha1_dst
			elif test $mod_dst = 160000
			then
				GIT_DIR="$name/.git" \
				git log --pretty='format:  > %s' -1 $sha1_dst
			else
				GIT_DIR="$name/.git" \
				git log --pretty='format:  < %s' -1 $sha1_src
			fi
			echo
		fi
		echo
	done |
	if test -n "$for_status"; then
		if [ -n "$files" ]; then
			echo "# Submodules changed but not updated:"
		else
			echo "# Submodule changes to be committed:"
		fi
		echo "#"
		sed -e 's|^|# |' -e 's|^# $|#|'
	else
		cat
	fi
}
#
# List all submodules, prefixed with:
#  - submodule not initialized
#  + different revision checked out
#
# If --cached was specified the revision in the index will be printed
# instead of the currently checked out revision.
#
# $@ = requested paths (default to all)
#
cmd_status()
{
	# parse $args after "submodule ... status".
	orig_args="$@"
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			;;
		--cached)
			cached=1
			;;
		--recursive)
			recursive=1
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	module_list "$@" |
	while read mode sha1 stage path
	do
		name=$(module_name "$path") || exit
		url=$(git config submodule."$name".url)
		displaypath="$prefix$path"
		if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
		then
			say "-$sha1 $displaypath"
			continue;
		fi
		set_name_rev "$path" "$sha1"
		if git diff-files --ignore-submodules=dirty --quiet -- "$path"
		then
			say " $sha1 $displaypath$revname"
		else
			if test -z "$cached"
			then
				sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
				set_name_rev "$path" "$sha1"
			fi
			say "+$sha1 $displaypath$revname"
		fi

		if test -n "$recursive"
		then
			(
				prefix="$displaypath/"
				clear_local_git_env
				cd "$path" &&
				cmd_status $orig_args
			) ||
			die "Failed to recurse into submodule path '$path'"
		fi
	done
}
#
# Sync remote urls for submodules
# This makes the value for remote.$remote.url match the value
# specified in .gitmodules.
#
cmd_sync()
{
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			shift
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
	done
	cd_to_toplevel
	module_list "$@" |
	while read mode sha1 stage path
	do
		name=$(module_name "$path")
		url=$(git config -f .gitmodules --get submodule."$name".url)

		# Possibly a url relative to parent
		case "$url" in
		./*|../*)
			url=$(resolve_relative_url "$url") || exit
			;;
		esac

		if test -e "$path"/.git
		then
		(
			say "Synchronizing submodule url for '$name'"
			git config submodule."$name".url "$url"
			clear_local_git_env
			cd "$path"
			remote=$(get_default_remote)
			git config remote."$remote".url "$url"
		)
		fi
	done
}

# This loop parses the command line arguments to find the
# subcommand name to dispatch.  Parsing of the subcommand specific
# options are primarily done by the subcommand implementations.
# Subcommand specific options such as --branch and --cached are
# parsed here as well, for backward compatibility.

while test $# != 0 && test -z "$command"
do
	case "$1" in
	add | foreach | init | update | status | summary | sync)
		command=$1
		;;
	-q|--quiet)
		GIT_QUIET=1
		;;
	-b|--branch)
		case "$2" in
		'')
			usage
			;;
		esac
		branch="$2"; shift
		;;
	--cached)
		cached="$1"
		;;
	--)
		break
		;;
	-*)
		usage
		;;
	*)
		break
		;;
	esac
	shift
done

# No command word defaults to "status"
test -n "$command" || command=status

# "-b branch" is accepted only by "add"
if test -n "$branch" && test "$command" != add
then
	usage
fi

# "--cached" is accepted only by "status" and "summary"
if test -n "$cached" && test "$command" != status -a "$command" != summary
then
	usage
fi

"cmd_$command" "$@"

[-- Attachment #3: git-submodule - Original --]
[-- Type: text/plain, Size: 19124 bytes --]

#!/bin/sh
#
# git-submodules.sh: add, init, update or list git submodules
#
# Copyright (c) 2007 Lars Hjemli

dashless=$(basename "$0" | sed -e 's/-/ /')
USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
   or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
   or: $dashless [--quiet] init [--] [<path>...]
   or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
   or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
   or: $dashless [--quiet] foreach [--recursive] <command>
   or: $dashless [--quiet] sync [--] [<path>...]"
OPTIONS_SPEC=
. git-sh-setup
. git-parse-remote
require_work_tree

command=
branch=
force=
reference=
cached=
recursive=
init=
files=
nofetch=
update=
prefix=

# Resolve relative url by appending to parent's url
resolve_relative_url ()
{
	remote=$(get_default_remote)
	remoteurl=$(git config "remote.$remote.url") ||
		die "remote ($remote) does not have a url defined in .git/config"
	url="$1"
	remoteurl=${remoteurl%/}
	while test -n "$url"
	do
		case "$url" in
		../*)
			url="${url#../}"
			remoteurl="${remoteurl%/*}"
			;;
		./*)
			url="${url#./}"
			;;
		*)
			break;;
		esac
	done
	echo "$remoteurl/${url%/}"
}

#
# Get submodule info for registered submodules
# $@ = path to limit submodule list
#
module_list()
{
	git ls-files --error-unmatch --stage -- "$@" | sane_grep '^160000 '
}

#
# Map submodule path to submodule name
#
# $1 = path
#
module_name()
{
	# Do we have "submodule.<something>.path = $1" defined in .gitmodules file?
	re=$(printf '%s\n' "$1" | sed -e 's/[].[^$\\*]/\\&/g')
	name=$( git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
		sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' )
       test -z "$name" &&
       die "No submodule mapping found in .gitmodules for path '$path'"
       echo "$name"
}

#
# Clone a submodule
#
# Prior to calling, cmd_update checks that a possibly existing
# path is not a git repository.
# Likewise, cmd_add checks that path does not exist at all,
# since it is the location of a new submodule.
#
module_clone()
{
	path=$1
	url=$2
	reference="$3"

	# If there already is a directory at the submodule path,
	# expect it to be empty (since that is the default checkout
	# action) and try to remove it.
	# Note: if $path is a symlink to a directory the test will
	# succeed but the rmdir will fail. We might want to fix this.
	if test -d "$path"
	then
		rmdir "$path" 2>/dev/null ||
		die "Directory '$path' exists, but is neither empty nor a git repository"
	fi

	test -e "$path" &&
	die "A file already exist at path '$path'"

	if test -n "$reference"
	then
		git-clone "$reference" -n "$url" "$path"
	else
		git-clone -n "$url" "$path"
	fi ||
	die "Clone of '$url' into submodule path '$path' failed"
}

#
# Add a new submodule to the working tree, .gitmodules and the index
#
# $@ = repo path
#
# optional branch is stored in global branch variable
#
cmd_add()
{
	# parse $args after "submodule ... add".
	while test $# -ne 0
	do
		case "$1" in
		-b | --branch)
			case "$2" in '') usage ;; esac
			branch=$2
			shift
			;;
		-f | --force)
			force=$1
			;;
		-q|--quiet)
			GIT_QUIET=1
			;;
		--reference)
			case "$2" in '') usage ;; esac
			reference="--reference=$2"
			shift
			;;
		--reference=*)
			reference="$1"
			shift
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	repo=$1
	path=$2

	if test -z "$path"; then
		path=$(echo "$repo" |
			sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
	fi

	if test -z "$repo" -o -z "$path"; then
		usage
	fi

	# assure repo is absolute or relative to parent
	case "$repo" in
	./*|../*)
		# dereference source url relative to parent's url
		realrepo=$(resolve_relative_url "$repo") || exit
		;;
	*:*|/*)
		# absolute url
		realrepo=$repo
		;;
	*)
		die "repo URL: '$repo' must be absolute or begin with ./|../"
	;;
	esac

	# normalize path:
	# multiple //; leading ./; /./; /../; trailing /
	path=$(printf '%s/\n' "$path" |
		sed -e '
			s|//*|/|g
			s|^\(\./\)*||
			s|/\./|/|g
			:start
			s|\([^/]*\)/\.\./||
			tstart
			s|/*$||
		')
	git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
	die "'$path' already exists in the index"

	if test -z "$force" && ! git add --dry-run --ignore-missing "$path" > /dev/null 2>&1
	then
		echo >&2 "The following path is ignored by one of your .gitignore files:" &&
		echo >&2 $path &&
		echo >&2 "Use -f if you really want to add it."
		exit 1
	fi

	# perhaps the path exists and is already a git repo, else clone it
	if test -e "$path"
	then
		if test -d "$path"/.git -o -f "$path"/.git
		then
			echo "Adding existing repo at '$path' to the index"
		else
			die "'$path' already exists and is not a valid git repo"
		fi

		case "$repo" in
		./*|../*)
			url=$(resolve_relative_url "$repo") || exit
		    ;;
		*)
			url="$repo"
			;;
		esac
		git config submodule."$path".url "$url"
	else

		module_clone "$path" "$realrepo" "$reference" || exit
		(
			clear_local_git_env
			cd "$path" &&
			# ash fails to wordsplit ${branch:+-b "$branch"...}
			case "$branch" in
			'') git checkout -f -q ;;
			?*) git checkout -f -q -b "$branch" "origin/$branch" ;;
			esac
		) || die "Unable to checkout submodule '$path'"
	fi

	git add $force "$path" ||
	die "Failed to add submodule '$path'"

	git config -f .gitmodules submodule."$path".path "$path" &&
	git config -f .gitmodules submodule."$path".url "$repo" &&
	git add --force .gitmodules ||
	die "Failed to register submodule '$path'"
}

#
# Execute an arbitrary command sequence in each checked out
# submodule
#
# $@ = command to execute
#
cmd_foreach()
{
	# parse $args after "submodule ... foreach".
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			;;
		--recursive)
			recursive=1
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	toplevel=$(pwd)

	module_list |
	while read mode sha1 stage path
	do
		if test -e "$path"/.git
		then
			say "Entering '$prefix$path'"
			name=$(module_name "$path")
			(
				prefix="$prefix$path/"
				clear_local_git_env
				cd "$path" &&
				eval "$@" &&
				if test -n "$recursive"
				then
					cmd_foreach "--recursive" "$@"
				fi
			) ||
			die "Stopping at '$path'; script returned non-zero status."
		fi
	done
}

#
# Register submodules in .git/config
#
# $@ = requested paths (default to all)
#
cmd_init()
{
	# parse $args after "submodule ... init".
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	module_list "$@" |
	while read mode sha1 stage path
	do
		# Skip already registered paths
		name=$(module_name "$path") || exit
		url=$(git config submodule."$name".url)
		test -z "$url" || continue

		url=$(git config -f .gitmodules submodule."$name".url)
		test -z "$url" &&
		die "No url found for submodule path '$path' in .gitmodules"

		# Possibly a url relative to parent
		case "$url" in
		./*|../*)
			url=$(resolve_relative_url "$url") || exit
			;;
		esac

		git config submodule."$name".url "$url" ||
		die "Failed to register url for submodule path '$path'"

		upd="$(git config -f .gitmodules submodule."$name".update)"
		test -z "$upd" ||
		git config submodule."$name".update "$upd" ||
		die "Failed to register update mode for submodule path '$path'"

		say "Submodule '$name' ($url) registered for path '$path'"
	done
}

#
# Update each submodule path to correct revision, using clone and checkout as needed
#
# $@ = requested paths (default to all)
#
cmd_update()
{
	# parse $args after "submodule ... update".
	orig_args="$@"
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			shift
			GIT_QUIET=1
			;;
		-i|--init)
			init=1
			shift
			;;
		-N|--no-fetch)
			shift
			nofetch=1
			;;
		-r|--rebase)
			shift
			update="rebase"
			;;
		--reference)
			case "$2" in '') usage ;; esac
			reference="--reference=$2"
			shift 2
			;;
		--reference=*)
			reference="$1"
			shift
			;;
		-m|--merge)
			shift
			update="merge"
			;;
		--recursive)
			shift
			recursive=1
			;;
		--save-progress)
			shift
			save_progress=1
			;;	
		--resume-update)
			shift
			submodule_resume=1
			;;				
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
	done

	if test -n "$init"
	then
		cmd_init "--" "$@" || return
	fi
	
	module_list "$@" |
	while read mode sha1 stage path
	do
		
		name=$(module_name "$path") || exit
		url=$(git config submodule."$name".url)
		update_module=$(git config submodule."$name".update)
		
		if test -n "$submodule_resume"
		then
			SubmodulePathResume=`pwd`
			SubmodulePathResume=$SubmodulePathResume/"$name"
			
			#SubmodulePathResume=$(pwd echo"'$name'")
			#say "'$SubmodulePathResume'"
			
			say $SubmodulePathResume
			AFile=`cat "Test.txt" | grep "$SubmodulePathResume"`
			
			say $AFile;
			
			if test -n "$AFile"
			then
				say "CancelRecursive"
				CancelRecursive=1
			else
				say "dupa"
				CancelRecursive=""
			fi			
		fi
		
		if test -z "$url"
		then
			# Only mention uninitialized submodules when its
			# path have been specified
			test "$#" != "0" &&
			say "Submodule path '$path' not initialized" &&
			say "Maybe you want to use 'update --init'?"
			continue
		fi

		if ! test -d "$path"/.git -o -f "$path"/.git
		then
			module_clone "$path" "$url" "$reference"|| exit
			subsha1=
		else
			subsha1=$(clear_local_git_env; cd "$path" &&
				git rev-parse --verify HEAD) ||
			die "Unable to find current revision in submodule path '$path'"
		fi

		if ! test -z "$update"
		then
			update_module=$update
		fi

		if test "$subsha1" != "$sha1"
		then
			force=
			if test -z "$subsha1"
			then
				force="-f"
			fi

			if test -z "$nofetch"
			then
				(clear_local_git_env; cd "$path" &&
					git-fetch) ||
				die "Unable to fetch in submodule path '$path'"
			fi
			
			if test -n "$submodule_resume"
			then
				update="resume"
			fi

			case "$update_module" in
			rebase)
				command="git rebase"
				action="rebase"
				msg="rebased onto"
				;;
			merge)
				command="git merge"
				action="merge"
				msg="merged in"
				;;
			*)
				command="git checkout $force -q"
				action="checkout"
				msg="checked out"
				;;
			resume)
				
				;;
			esac

			(clear_local_git_env; cd "$path" && $command "$sha1") ||
			die "Unable to $action '$sha1' in submodule path '$path'"
			say "Submodule path '$path': $msg '$sha1'"
		fi
	
		if test -n "$recursive"
		then
			if test -z "$CancelRecursive"
			then
				(clear_local_git_env; cd "$path" && cmd_update $orig_args) ||
				die "Failed to recurse into submodule path '$path'"
			fi
		fi
		
		if test -n "$save_progress"
		then
				SubmodulePath=`pwd`
				SubmodulePath=$SubmodulePath/"$name"
				
				#SubmodulePath=$(pwd echo"'$name'")
				say "'$SubmodulePath'"
				echo "'$SubmodulePath'" >> Test.txt
		fi
	done
}

set_name_rev () {
	revname=$( (
		clear_local_git_env
		cd "$1" && {
			git describe "$2" 2>/dev/null ||
			git describe --tags "$2" 2>/dev/null ||
			git describe --contains "$2" 2>/dev/null ||
			git describe --all --always "$2"
		}
	) )
	test -z "$revname" || revname=" ($revname)"
}
#
# Show commit summary for submodules in index or working tree
#
# If '--cached' is given, show summary between index and given commit,
# or between working tree and given commit
#
# $@ = [commit (default 'HEAD'),] requested paths (default all)
#
cmd_summary() {
	summary_limit=-1
	for_status=
	diff_cmd=diff-index

	# parse $args after "submodule ... summary".
	while test $# -ne 0
	do
		case "$1" in
		--cached)
			cached="$1"
			;;
		--files)
			files="$1"
			;;
		--for-status)
			for_status="$1"
			;;
		-n|--summary-limit)
			if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
			then
				:
			else
				usage
			fi
			shift
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	test $summary_limit = 0 && return

	if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
	then
		head=$rev
		test $# = 0 || shift
	elif test -z "$1" -o "$1" = "HEAD"
	then
		# before the first commit: compare with an empty tree
		head=$(git hash-object -w -t tree --stdin </dev/null)
		test -z "$1" || shift
	else
		head="HEAD"
	fi

	if [ -n "$files" ]
	then
		test -n "$cached" &&
		die "--cached cannot be used with --files"
		diff_cmd=diff-files
		head=
	fi

	cd_to_toplevel
	# Get modified modules cared by user
	modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
		sane_egrep '^:([0-7]* )?160000' |
		while read mod_src mod_dst sha1_src sha1_dst status name
		do
			# Always show modules deleted or type-changed (blob<->module)
			test $status = D -o $status = T && echo "$name" && continue
			# Also show added or modified modules which are checked out
			GIT_DIR="$name/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
			echo "$name"
		done
	)

	test -z "$modules" && return

	git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
	sane_egrep '^:([0-7]* )?160000' |
	cut -c2- |
	while read mod_src mod_dst sha1_src sha1_dst status name
	do
		if test -z "$cached" &&
			test $sha1_dst = 0000000000000000000000000000000000000000
		then
			case "$mod_dst" in
			160000)
				sha1_dst=$(GIT_DIR="$name/.git" git rev-parse HEAD)
				;;
			100644 | 100755 | 120000)
				sha1_dst=$(git hash-object $name)
				;;
			000000)
				;; # removed
			*)
				# unexpected type
				echo >&2 "unexpected mode $mod_dst"
				continue ;;
			esac
		fi
		missing_src=
		missing_dst=

		test $mod_src = 160000 &&
		! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_src^0 >/dev/null &&
		missing_src=t

		test $mod_dst = 160000 &&
		! GIT_DIR="$name/.git" git-rev-parse -q --verify $sha1_dst^0 >/dev/null &&
		missing_dst=t

		total_commits=
		case "$missing_src,$missing_dst" in
		t,)
			errmsg="  Warn: $name doesn't contain commit $sha1_src"
			;;
		,t)
			errmsg="  Warn: $name doesn't contain commit $sha1_dst"
			;;
		t,t)
			errmsg="  Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
			;;
		*)
			errmsg=
			total_commits=$(
			if test $mod_src = 160000 -a $mod_dst = 160000
			then
				range="$sha1_src...$sha1_dst"
			elif test $mod_src = 160000
			then
				range=$sha1_src
			else
				range=$sha1_dst
			fi
			GIT_DIR="$name/.git" \
			git rev-list --first-parent $range -- | wc -l
			)
			total_commits=" ($(($total_commits + 0)))"
			;;
		esac

		sha1_abbr_src=$(echo $sha1_src | cut -c1-7)
		sha1_abbr_dst=$(echo $sha1_dst | cut -c1-7)
		if test $status = T
		then
			if test $mod_dst = 160000
			then
				echo "* $name $sha1_abbr_src(blob)->$sha1_abbr_dst(submodule)$total_commits:"
			else
				echo "* $name $sha1_abbr_src(submodule)->$sha1_abbr_dst(blob)$total_commits:"
			fi
		else
			echo "* $name $sha1_abbr_src...$sha1_abbr_dst$total_commits:"
		fi
		if test -n "$errmsg"
		then
			# Don't give error msg for modification whose dst is not submodule
			# i.e. deleted or changed to blob
			test $mod_dst = 160000 && echo "$errmsg"
		else
			if test $mod_src = 160000 -a $mod_dst = 160000
			then
				limit=
				test $summary_limit -gt 0 && limit="-$summary_limit"
				GIT_DIR="$name/.git" \
				git log $limit --pretty='format:  %m %s' \
				--first-parent $sha1_src...$sha1_dst
			elif test $mod_dst = 160000
			then
				GIT_DIR="$name/.git" \
				git log --pretty='format:  > %s' -1 $sha1_dst
			else
				GIT_DIR="$name/.git" \
				git log --pretty='format:  < %s' -1 $sha1_src
			fi
			echo
		fi
		echo
	done |
	if test -n "$for_status"; then
		if [ -n "$files" ]; then
			echo "# Submodules changed but not updated:"
		else
			echo "# Submodule changes to be committed:"
		fi
		echo "#"
		sed -e 's|^|# |' -e 's|^# $|#|'
	else
		cat
	fi
}
#
# List all submodules, prefixed with:
#  - submodule not initialized
#  + different revision checked out
#
# If --cached was specified the revision in the index will be printed
# instead of the currently checked out revision.
#
# $@ = requested paths (default to all)
#
cmd_status()
{
	# parse $args after "submodule ... status".
	orig_args="$@"
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			;;
		--cached)
			cached=1
			;;
		--recursive)
			recursive=1
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
		shift
	done

	module_list "$@" |
	while read mode sha1 stage path
	do
		name=$(module_name "$path") || exit
		url=$(git config submodule."$name".url)
		displaypath="$prefix$path"
		if test -z "$url" || ! test -d "$path"/.git -o -f "$path"/.git
		then
			say "-$sha1 $displaypath"
			continue;
		fi
		set_name_rev "$path" "$sha1"
		if git diff-files --ignore-submodules=dirty --quiet -- "$path"
		then
			say " $sha1 $displaypath$revname"
		else
			if test -z "$cached"
			then
				sha1=$(clear_local_git_env; cd "$path" && git rev-parse --verify HEAD)
				set_name_rev "$path" "$sha1"
			fi
			say "+$sha1 $displaypath$revname"
		fi

		if test -n "$recursive"
		then
			(
				prefix="$displaypath/"
				clear_local_git_env
				cd "$path" &&
				cmd_status $orig_args
			) ||
			die "Failed to recurse into submodule path '$path'"
		fi
	done
}
#
# Sync remote urls for submodules
# This makes the value for remote.$remote.url match the value
# specified in .gitmodules.
#
cmd_sync()
{
	while test $# -ne 0
	do
		case "$1" in
		-q|--quiet)
			GIT_QUIET=1
			shift
			;;
		--)
			shift
			break
			;;
		-*)
			usage
			;;
		*)
			break
			;;
		esac
	done
	cd_to_toplevel
	module_list "$@" |
	while read mode sha1 stage path
	do
		name=$(module_name "$path")
		url=$(git config -f .gitmodules --get submodule."$name".url)

		# Possibly a url relative to parent
		case "$url" in
		./*|../*)
			url=$(resolve_relative_url "$url") || exit
			;;
		esac

		if test -e "$path"/.git
		then
		(
			say "Synchronizing submodule url for '$name'"
			git config submodule."$name".url "$url"
			clear_local_git_env
			cd "$path"
			remote=$(get_default_remote)
			git config remote."$remote".url "$url"
		)
		fi
	done
}

# This loop parses the command line arguments to find the
# subcommand name to dispatch.  Parsing of the subcommand specific
# options are primarily done by the subcommand implementations.
# Subcommand specific options such as --branch and --cached are
# parsed here as well, for backward compatibility.

while test $# != 0 && test -z "$command"
do
	case "$1" in
	add | foreach | init | update | status | summary | sync)
		command=$1
		;;
	-q|--quiet)
		GIT_QUIET=1
		;;
	-b|--branch)
		case "$2" in
		'')
			usage
			;;
		esac
		branch="$2"; shift
		;;
	--cached)
		cached="$1"
		;;
	--)
		break
		;;
	-*)
		usage
		;;
	*)
		break
		;;
	esac
	shift
done

# No command word defaults to "status"
test -n "$command" || command=status

# "-b branch" is accepted only by "add"
if test -n "$branch" && test "$command" != add
then
	usage
fi

# "--cached" is accepted only by "status" and "summary"
if test -n "$cached" && test "$command" != status -a "$command" != summary
then
	usage
fi

"cmd_$command" "$@"

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

* Re: Restart submodule update --recursive
  2010-10-29 11:37       ` Lukasz Palczewski
@ 2010-10-29 16:40         ` Jonathan Nieder
  2010-10-30  7:17         ` Jens Lehmann
  1 sibling, 0 replies; 11+ messages in thread
From: Jonathan Nieder @ 2010-10-29 16:40 UTC (permalink / raw)
  To: Lukasz Palczewski; +Cc: git, Johan Herland, Jens Lehmann, Piotrek Pientka

Hi again,

Lukasz Palczewski wrote:
> Jonathan Nieder wrote:

>> [side note: if you use a newsreader, please reply by mail instead of
>> through gmane so the Cc: list can be preserved.]
>
> Sorry, but I do not use it. I will send You a normal email.

Thanks.

> I have added two options to git submodule update:
> --save-progress
> --resume-update
> First one You can use, to save the ./.git/SubmoduleUpdateLog.log the
> progress of updating:
> git submodule update --recursive --save-progress
> The second one is used for skipping updated submodules:
> git submodule update --recursive --resume-update
> 
> The downside of it is, that u can use only one --resume-update.

Does the combination
"git submodule update --recursive --save-progress --resume-update"
work?

> Let me know if this change will be in next version of git.

I will leave that question to the submodule experts.  But note that
there is no need to wait: if you change the ". git-sh-setup" line
to

	. "$(git --exec-path)/git-sh-setup"

then if you install the modified script as git-mysubmodule anywhere on
your $PATH, it will be used to implement

	git mysubmodule update --recursive --save-progress

.  Of course you can run it directly as "git-mysubmodule", too.

diffs are easier to review.  If your change is for inclusion, it will
also need a Signed-off-by: line; see Documentation/SubmittingPatches.

> cmd_update()
> {
[...]
> 		--save-progress)
> 			shift
> 			save_progress=1
> 			if test -e ./.git/SubmoduleUpdateLog.log
> 			then
> 				rm ./.git/SubmoduleUpdateLog.log
> 			fi

Some current temporary files used by git:

	.git/rr-cache/*
	.git/gitk.cache
	.git/rebase-merge/*
	.git/rebase-apply/*

The
	if test -e $foo
	then
		rm $foo
	fi

idiom can be written more simply as

	rm -f $foo

but are you sure that is what you want?  Maybe it would be better
to

	1) destroy progress when the update is completed
	2) always save updated progress when resuming
	3) complain when --save-progress would require clobbering
	   some existing progress
	4) provide an additional --reset-progress option to start
	   over

?

FWIW "git am" and "git rebase" already have the ability to resume
where they left off, using options with these names:

	git <foo> --continue
	git <foo> --skip
	git <foo> --abort

The --abort options undo the effect of the earlier runs.  "git bisect"
also keeps some state on progress.

	git bisect (good|bad); # continue
	git bisect skip
	git bisect reset

> 	module_list "$@" |
> 	while read mode sha1 stage path
> 	do		
> 		name=$(module_name "$path") || exit
> 		url=$(git config submodule."$name".url)
> 		update_module=$(git config submodule."$name".update)
> 		
> 		if test -n "$submodule_resume"
> 		then
> 			SubmodulePathResume=`pwd`
> 			SubmodulePathResume=$SubmodulePathResume/"$name"

It might be more idiomatic to say

	module_list "$@" |
	...
			(
				prefix="$prefix$path/"

Three benefits:

 - local variables tend to get short, lowercase names
 - this variable looks like a path, but using $name makes it not
   one (if foo/bar is a submodule simple named "bar", for example)
 - using relative paths allows an update to be resumed after moving
   a repository or just accessing it via a different path.

The subshell ensures the old prefix is restored when cmd_update
returns.  The same effect could also be achieved by saving the old
prefix (in case it is important to save a few processes).

> 			
> 			#say $SubmodulePathResume
> 			if test -e ./.git/SubmoduleUpdateLog.log

What if I try to resume and there is no progress information?
Would it make sense to keep the progress information at the toplevel,
so one could run commands like "submodule update --recursive
--resumable" in submodules without affecting the superproject state?


> 			then
> 				AFile=`cat "./.git/SubmoduleUpdateLog.log" | grep "$SubmodulePathResume"`
> 				
> 				#say $AFile;			
> 				if test -n "$AFile"

The following could work if each submodule is written to
submodule-update.log only if all its submodules have been updated
(as in your current code):

		if git grep --no-index -q -F "$prefix" "$GIT_DIR/submodule-update.log"
		then
			say "Skip...
			continue
		fi

I'm not sure fgrep is portable, which is why I use "git grep" here.

This is slower than it could be.  Ideally one would only keep
the last updated submodule and chop the module_list output there,
instead of re-reading the list with each iteration (which is O(size of
directory squared)).

Hope that helps,
Jonathan

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

* Re: Restart submodule update --recursive
  2010-10-29 11:37       ` Lukasz Palczewski
  2010-10-29 16:40         ` Jonathan Nieder
@ 2010-10-30  7:17         ` Jens Lehmann
  2010-11-02  8:18           ` Lukasz Palczewski
  1 sibling, 1 reply; 11+ messages in thread
From: Jens Lehmann @ 2010-10-30  7:17 UTC (permalink / raw)
  To: Lukasz Palczewski; +Cc: git, Jonathan Nieder

>Let me know if this change will be in next version of git.

Sorry I'm coming late into this thread,but I'm still traveling.

Lukasz, maybe you could wait until I finish the recursive checkout I am
currently working on? Because then there will be no need to run
"git submodule update" anymore, but "git checkout" will update
submodules recursively too. And it will only fail if the checkout would
overwrite your local modifications, not just because the submodule is
modified in some way, and in this case it won't start at all instead of stopping
somewhere in between (you can test that new behavior by checking
out the branch "enhance_git_for_submodules" of my github repo:
http://github.com/jlehmann/git-submod-enhancements ).

Would that solve your problem?

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

* Re: Restart submodule update --recursive
  2010-10-30  7:17         ` Jens Lehmann
@ 2010-11-02  8:18           ` Lukasz Palczewski
  2010-11-02 11:08             ` Jens Lehmann
  0 siblings, 1 reply; 11+ messages in thread
From: Lukasz Palczewski @ 2010-11-02  8:18 UTC (permalink / raw)
  To: Jens Lehmann; +Cc: git, Jonathan Nieder

Jens Lehmann wrote:
>> Let me know if this change will be in next version of git.
> Sorry I'm coming late into this thread,but I'm still traveling.
>
> Lukasz, maybe you could wait until I finish the recursive checkout I am
> currently working on? Because then there will be no need to run
> "git submodule update" anymore, but "git checkout" will update
> submodules recursively too. And it will only fail if the checkout would
> overwrite your local modifications, not just because the submodule is
> modified in some way, and in this case it won't start at all instead of stopping
> somewhere in between (you can test that new behavior by checking
> out the branch "enhance_git_for_submodules" of my github repo:
> http://github.com/jlehmann/git-submod-enhancements ).
>
> Would that solve your problem?

Hi Jens,
Well I will wait for it and see if it does, but it will not solve all 
the problems.
Once I had a problem, when someone forgot to push a commit in the 
submodule, but pushed a commit in the main repository. Becouse of it, I 
could not update that repository. If this problem occours, I will have 
to update all the submodules with the one command "git submodules update 
--recursive" (when someone finally pushes the submodule). If the "git 
checkout" updates the rest ( not updated) submodules, but not check the 
ones, that were updated earlier, then it will work for me.

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

* Re: Restart submodule update --recursive
  2010-11-02  8:18           ` Lukasz Palczewski
@ 2010-11-02 11:08             ` Jens Lehmann
  0 siblings, 0 replies; 11+ messages in thread
From: Jens Lehmann @ 2010-11-02 11:08 UTC (permalink / raw)
  To: Lukasz Palczewski; +Cc: git, Jonathan Nieder

Am 02.11.2010 09:18, schrieb Lukasz Palczewski:
> Well I will wait for it and see if it does, but it will not solve all the problems.

Thanks, as we are moving more submodule functionality into the git
commands I would rather avoid adding new stuff to git-submodule.sh
unless it is something not handled by that move.

> Once I had a problem, when someone forgot to push a commit in the
> submodule, but pushed a commit in the main repository.

Yes, this is a common problem. We'll add a test for that in "git push"
soon, then it won't be possible to do that by accident anymore.

> Becouse of it, I could not update that repository. If this problem
> occours, I will have to update all the submodules with the one
> command "git submodules update --recursive" (when someone finally
> pushes the submodule). If the "git checkout" updates the rest
> ( not updated) submodules, but not check the ones, that were updated
> earlier, then it will work for me.

As the functionality which is now done by "git submodule update"
will be split into recursive fetch and recursive checkout, you would
have to issue a "git fetch --recurse-submodules" to retrieve the
missing commits. But that shouldn't be necessary when "git push"
tests for all submodule commits to be pushed too before it pushes
the superproject.

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

end of thread, other threads:[~2010-11-02 11:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-28  7:25 Restart submodule update --recursive Lukasz Palczewski
2010-10-28 10:35 ` Johan Herland
2010-10-29  7:28   ` Lukasz Palczewski
2010-10-28 18:15 ` Jonathan Nieder
2010-10-29  7:17   ` Lukasz Palczewski
2010-10-29  9:12     ` Jonathan Nieder
2010-10-29 11:37       ` Lukasz Palczewski
2010-10-29 16:40         ` Jonathan Nieder
2010-10-30  7:17         ` Jens Lehmann
2010-11-02  8:18           ` Lukasz Palczewski
2010-11-02 11:08             ` Jens Lehmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.