From: Johannes Schindelin Date: Thu, 22 Dec 2005 22:37:24 +0000 (+0100) Subject: git-clone: Support changing the origin branch with -o X-Git-Tag: v1.1.0~33 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e6c310fd0d7384973efc6b1d5999a5e8a5b2f3bd;p=git.git 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 '. [jc: added ref format check, subdirectory safety, documentation and usage string.] Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 8410a6d3..f943f267 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -8,7 +8,7 @@ git-clone - Clones a repository. SYNOPSIS -------- -'git-clone' [-l [-s]] [-q] [-n] [-u ] [] +'git-clone' [-l [-s]] [-q] [-n] [-o ] [-u ] [] DESCRIPTION ----------- @@ -56,6 +56,13 @@ OPTIONS -n:: No checkout of HEAD is performed after the clone is complete. +-o :: + Instead of using the branch name 'origin' to keep track + of the upstream repository, use 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 :: -u :: When given, and the repository to clone from is handled diff --git a/git-clone.sh b/git-clone.sh index 280cc2e8..bfc6c2d7 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -9,7 +9,7 @@ unset CDPATH usage() { - echo >&2 "Usage: $0 [-l [-s]] [-q] [-u ] [-n] []" + echo >&2 "Usage: $0 [-l [-s]] [-q] [-u ] [-o ] [-n] []" exit 1 } @@ -67,6 +67,7 @@ use_local=no local_shared=no no_checkout= upload_pack= +origin=origin while case "$#,$1" in 0,*) break ;; @@ -75,6 +76,14 @@ while *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared) local_shared=yes; use_local=yes ;; *,-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 ;; *,-u|*,--upload-pack) shift @@ -208,14 +217,14 @@ then mkdir -p .git/remotes && echo >.git/remotes/origin \ "URL: $repo -Pull: $head_points_at:origin" && - cp ".git/refs/heads/$head_points_at" .git/refs/heads/origin && +Pull: $head_points_at:$origin" && + git-update-ref "refs/heads/$origin" $(git-rev-parse HEAD) && find .git/refs/heads -type f -print | while read ref do head=`expr "$ref" : '.git/refs/heads/\(.*\)'` && test "$head_points_at" = "$head" || - test "origin" = "$head" || + test "$origin" = "$head" || echo "Pull: ${head}:${head}" done >>.git/remotes/origin esac