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>
Johannes Schindelin committed
Dec 22, 2005 at 23:37 UTC
e6c310fd0d7384973efc6b1d5999a5e8a5b2f3bd
2 files changed
+21
-5
Documentation/git-clone.txt
+8
-1
@@ -8,7 +8,7 @@ git-clone - Clones a repository.
8
9
SYNOPSIS
10
--------
11
-'git-clone' [-l [-s]] [-q] [-n] [-u <upload-pack>] <repository> [<directory>]
11
+'git-clone' [-l [-s]] [-q] [-n] [-o <name>] [-u <upload-pack>] <repository> [<directory>]
12
13
DESCRIPTION
14
-----------
@@ -56,6 +56,13 @@ OPTIONS
56
-n::
57
No checkout of HEAD is performed after the clone is complete.
58
59
+-o <name>::
60
+ Instead of using the branch name 'origin' to keep track
61
+ of the upstream repository, use <name> instead. Note
62
+ that the shorthand name stored in `remotes/origin` is
63
+ not affected, but the local branch name to pull the
64
+ remote `master` branch into is.
65
+
66
--upload-pack <upload-pack>::
67
-u <upload-pack>::
68
When given, and the repository to clone from is handled
git-clone.sh
+13
-4
@@ -9,7 +9,7 @@
9
unset CDPATH
10
11
usage() {
12
- echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-n] <repo> [<dir>]"
12
+ echo >&2 "Usage: $0 [-l [-s]] [-q] [-u <upload-pack>] [-o <name>] [-n] <repo> [<dir>]"
13
exit 1
14
}
15
@@ -67,6 +67,7 @@ use_local=no
67
local_shared=no
68
no_checkout=
69
upload_pack=
70
+origin=origin
71
while
72
case "$#,$1" in
73
0,*) break ;;
@@ -75,6 +76,14 @@ while
76
*,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared)
77
local_shared=yes; use_local=yes ;;
78
*,-q|*,--quiet) quiet=-q ;;
79
+ 1,-o) usage;;
80
+ *,-o)
81
+ git-check-ref-format "$2" || {
82
+ echo >&2 "'$2' is not suitable for a branch name"
83
+ exit 1
84
+ }
85
+ origin="$2"; shift
86
+ ;;
87
1,-u|1,--upload-pack) usage ;;
88
*,-u|*,--upload-pack)
89
shift
@@ -208,14 +217,14 @@ then
217
mkdir -p .git/remotes &&
218
echo >.git/remotes/origin \
219
"URL: $repo
211
-Pull: $head_points_at:origin" &&
212
- cp ".git/refs/heads/$head_points_at" .git/refs/heads/origin &&
220
+Pull: $head_points_at:$origin" &&
221
+ git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) &&
222
find .git/refs/heads -type f -print |
223
while read ref
224
do
225
head=`expr "$ref" : '.git/refs/heads/\(.*\)'` &&
226
test "$head_points_at" = "$head" ||
218
- test "origin" = "$head" ||
227
+ test "$origin" = "$head" ||
228
echo "Pull: ${head}:${head}"
229
done >>.git/remotes/origin
230
esac