# # GAWK script to extract both path and remote definitions from a # git submodule foreach --recursive git remote -v # run. # BEGIN { submodule_path = "."; idx = 0; printf("#! /bin/bash\n"); printf("# generated by collect_git_add_recursively.sh\n"); printf("\n"); printf("pushd $(dirname $0) 2> /dev/null > /dev/null\n"); printf("cd ..\n"); printf("\n"); printf("mode=\"d\"\n"); printf("\n"); printf("getopts \":fqh\" opt\n"); printf("#echo opt+arg = \"$opt$OPTARG\"\n"); printf("case \"$opt$OPTARG\" in\n"); printf("f )\n"); printf(" echo \"--- check out master/HEAD before registering all git remotes ---\"\n"); printf(" for (( i=OPTIND; i > 1; i-- )) do\n"); printf(" shift\n"); printf(" done\n"); printf(" #echo args: $@\n"); printf(" mode=\"f\"\n"); printf("\n"); printf(" git submodule sync\n"); printf(" git submodule update --init\n"); printf(" git submodule update --init --recursive\n"); printf("\n"); printf(" util/git_checkout_submodules_head.sh\n"); printf(" ;;\n"); printf("\n"); printf("\"?\" )\n"); printf(" echo \"--- set up git remotes only ---\"\n"); printf(" ;;\n"); printf("\n"); printf("q )\n"); printf(" echo \"--- set up git remotes only ---\"\n"); printf(" for (( i=OPTIND; i > 1; i-- )) do\n"); printf(" shift\n"); printf(" done\n"); printf(" #echo args: $@\n"); printf(" mode=\"q\"\n"); printf(" ;;\n"); printf("\n"); printf("* )\n"); printf(" cat < /dev/null > /dev/null\n"); printf(" if test \"$mode\" = \"f\" ; then\n"); printf(" git remote rm $name\n"); printf(" fi\n"); printf(" git remote add $name $repo\n"); printf(" popd 2> /dev/null > /dev/null\n"); printf(" fi\n"); printf(" fi\n"); printf("}\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); } /Entering '/ { # because MSys gawk doesn't support match() with 3 arguments :-(( split($0, a, "'"); submodule_path = a[2]; #printf("Selecting path [%s]\n", submodule_path); next; } /\(fetch\)/ { #printf("line: [%s] %d\n", " " $0, match(":: " $0, /[\t ]origin[\t ]/), match(":: " $0, /[\t ]Win7DEV[\t ]/)); if (match(" " $0, /[\t ]origin[\t ]/)) { #printf("skipped line: [%s]\n", $0); next; } if (match(" " $0, /[\t ]Win7DEV[\t ]/)) { next; } name = $1; uri = $2; # make sure all remotes use 'public' URIs: sub(/git@github\.com:/, "git://github.com/", uri); sub(/git:\/\/github\.com\//, "git@github.com:", uri); stmts[++idx] = sprintf("register_remote %-60s %-40s %-80s $# $@", submodule_path, name, uri); #printf("# id %d: %s\n", idx, stmts[idx]); next; } { next; } END { asort(stmts); for (i = 1; i <= idx; i++) { printf("%s\n", stmts[i]); } printf("\n"); printf("\n"); printf("\n"); printf("popd 2> /dev/null > /dev/null\n"); printf("\n"); }