git-clone: Support changing the origin branch with -o
Earlier, git-clone stored upstream's master in the branch named 'origin', possibly overwriting an existing such branch. Now you can change it by calling git-clone with '-o <other_name>'. [jc: added ref format check, subdirectory safety, documentation and usage string.] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>maint
parent
356bece0a2
commit
e6c310fd0d
|
@ -8,7 +8,7 @@ git-clone - Clones a repository.
|
||||||
|
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
'git-clone' [-l [-s]] [-q] [-n] [-u <upload-pack>] <repository> [<directory>]
|
'git-clone' [-l [-s]] [-q] [-n] [-o <name>] [-u <upload-pack>] <repository> [<directory>]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -56,6 +56,13 @@ OPTIONS
|
||||||
-n::
|
-n::
|
||||||
No checkout of HEAD is performed after the clone is complete.
|
No checkout of HEAD is performed after the clone is complete.
|
||||||
|
|
||||||
|
-o <name>::
|
||||||
|
Instead of using the branch name 'origin' to keep track
|
||||||
|
of the upstream repository, use <name> instead. Note
|
||||||
|
that the shorthand name stored in `remotes/origin` is
|
||||||
|
not affected, but the local branch name to pull the
|
||||||
|
remote `master` branch into is.
|
||||||
|
|
||||||
--upload-pack <upload-pack>::
|
--upload-pack <upload-pack>::
|
||||||
-u <upload-pack>::
|
-u <upload-pack>::
|
||||||
When given, and the repository to clone from is handled
|
When given, and the repository to clone from is handled
|
||||||
|
|
17
git-clone.sh
17
git-clone.sh
|
@ -9,7 +9,7 @@
|
||||||
unset CDPATH
|
unset CDPATH
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
|
echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-o <name>] [-n] <repo> [<dir>]"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ use_local=no
|
||||||
local_shared=no
|
local_shared=no
|
||||||
no_checkout=
|
no_checkout=
|
||||||
upload_pack=
|
upload_pack=
|
||||||
|
origin=origin
|
||||||
while
|
while
|
||||||
case "$#,$1" in
|
case "$#,$1" in
|
||||||
0,*) break ;;
|
0,*) break ;;
|
||||||
|
@ -75,6 +76,14 @@ while
|
||||||
*,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)
|
*,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)
|
||||||
local_shared=yes; use_local=yes ;;
|
local_shared=yes; use_local=yes ;;
|
||||||
*,-q|*,--quiet) quiet=-q ;;
|
*,-q|*,--quiet) quiet=-q ;;
|
||||||
|
1,-o) usage;;
|
||||||
|
*,-o)
|
||||||
|
git-check-ref-format "$2" || {
|
||||||
|
echo >&2 "'$2' is not suitable for a branch name"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
origin="$2"; shift
|
||||||
|
;;
|
||||||
1,-u|1,--upload-pack) usage ;;
|
1,-u|1,--upload-pack) usage ;;
|
||||||
*,-u|*,--upload-pack)
|
*,-u|*,--upload-pack)
|
||||||
shift
|
shift
|
||||||
|
@ -208,14 +217,14 @@ then
|
||||||
mkdir -p .git/remotes &&
|
mkdir -p .git/remotes &&
|
||||||
echo >.git/remotes/origin \
|
echo >.git/remotes/origin \
|
||||||
"URL: $repo
|
"URL: $repo
|
||||||
Pull: $head_points_at:origin" &&
|
Pull: $head_points_at:$origin" &&
|
||||||
cp ".git/refs/heads/$head_points_at" .git/refs/heads/origin &&
|
git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) &&
|
||||||
find .git/refs/heads -type f -print |
|
find .git/refs/heads -type f -print |
|
||||||
while read ref
|
while read ref
|
||||||
do
|
do
|
||||||
head=`expr "$ref" : '.git/refs/heads/\(.*\)'` &&
|
head=`expr "$ref" : '.git/refs/heads/\(.*\)'` &&
|
||||||
test "$head_points_at" = "$head" ||
|
test "$head_points_at" = "$head" ||
|
||||||
test "origin" = "$head" ||
|
test "$origin" = "$head" ||
|
||||||
echo "Pull: ${head}:${head}"
|
echo "Pull: ${head}:${head}"
|
||||||
done >>.git/remotes/origin
|
done >>.git/remotes/origin
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in New Issue