I propose that the origin of a branch comes from a file in .git/branches/ of the same name. So the origin of default branch master is the content of the file .git/branches/master that in the current practice would be "origin". But we could have the remote branch "git", being the origin of the local branch "git_dirs" (the content of .git/branches/git_dirs = "git"). The origin branch is reserved. When you cg-clone the origin is now called cloned (but "commit-id cloned" = "commit-id origin" while you do not switch to another branch whith other origin). The transition from old handling is not in the patch. So now you can: cg-clone -s rsync://rsync.kernel.org/pub/scm/git/git.git/ and work in this in your "master" branch with origin "cloned". You can add another repository: cg-branch-add pb http://pasky.or.cz/~pasky/dev/git/git-pb.git cg-pull pb and if you want to do some modifications based on pb: cg-branch-add pb-sb pb ln -s refs/heads/pb-sb .git/HEAD commit-id pb > .git/HEAD git-read-tree HEAD git-checkout-cache -f -q -u -a and work on your branch. The last four lines are the work of the hipothetical cg-branch-switch. Signed-off-by: "Santi Béjar" <sbejar@gmail.com> --- cg-Xnormid | 6 ++++++ cg-branch-add | 2 +- cg-clone | 2 +- cg-commit | 7 ++++++- cg-init | 9 +++++---- cg-merge | 7 ++++++- cg-pull | 7 ++++++- 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/cg-Xnormid b/cg-Xnormid --- a/cg-Xnormid +++ b/cg-Xnormid @@ -6,6 +6,7 @@ # # Strings resolve in this order: # NULL, this, HEAD => .git/HEAD +# origin => origin of the branch # <tags> # <heads> # short SHA1 (4 or more hex digits) @@ -19,6 +20,11 @@ id="$1" if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then read id < "$_git/HEAD" +elif [ "$id" = "origin" ]; then + branch=$(readlink $_git/HEAD | sed 's@refs/heads/@@') + origin=$(cat $_git/branches/$branch) + read id < "$_git/refs/heads/$origin" + elif [ -r "$_git/refs/tags/$id" ]; then read id < "$_git/refs/tags/$id" diff --git a/cg-branch-add b/cg-branch-add --- a/cg-branch-add +++ b/cg-branch-add @@ -40,7 +40,7 @@ location=$2 ([ "$name" ] && [ "$location" ]) || usage (echo $name | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \ die "name contains invalid characters" -if [ "$name" = "this" ] || [ "$name" = "HEAD" ]; then +if [ "$name" = "this" ] || [ "$name" = "HEAD" ] || [ "$name" = "origin" ]; then die "given branch name is reserved" fi diff --git a/cg-clone b/cg-clone --- a/cg-clone +++ b/cg-clone @@ -56,4 +56,4 @@ fi trap "rm -rf $dir" SIGTERM EXIT cg-init $location || exit $? trap "" SIGTERM EXIT -echo "Cloned to $dir/ (origin $location available as branch \"origin\")" +echo "Cloned to $dir/ (origin $location available as branch \"cloned\")" diff --git a/cg-commit b/cg-commit --- a/cg-commit +++ b/cg-commit @@ -141,7 +141,12 @@ if [ "$merging" ]; then [ "$msgs" ] && echo -n 'Merge with ' [ -s $_git/merging-sym ] || cp $_git/merging $_git/merging-sym for sym in $(cat $_git/merging-sym); do - uri=$(cat $_git/branches/$sym) + if [ $sym = origin ] ; then + branch=$(readlink $_git/HEAD | sed 's@refs/heads/@@') + uri=$(cat $_git/branches/$branch) + else + uri=$(cat $_git/branches/$sym) + fi [ "$uri" ] || uri="$sym" echo "$uri" >>$LOGMSG [ "$msgs" ] && echo "$uri" diff --git a/cg-init b/cg-init --- a/cg-init +++ b/cg-init @@ -26,15 +26,16 @@ mkdir $_git/branches touch $_git/refs/heads/master if [ "$uri" ]; then - echo "$uri" >$_git/branches/origin - cg-pull origin || die "pull failed" + echo "$uri" >$_git/branches/cloned + echo cloned >$_git/branches/master + cg-pull cloned || die "pull failed" - cp $_git/refs/heads/origin $_git/refs/heads/master + cp $_git/refs/heads/cloned $_git/refs/heads/master git-read-tree HEAD git-checkout-cache -a git-update-cache --refresh - echo "Cloned (origin $uri available as branch \"origin\")" + echo "Cloned (cloned $uri available as branch \"cloned\")" else git-read-tree # Seed the dircache find * \( -type f -o -type l \) -print0 | xargs -0r cg-add diff --git a/cg-pull b/cg-pull --- a/cg-pull +++ b/cg-pull @@ -14,10 +14,15 @@ USAGE="cg-pull [BRANCH_NAME]" name=$1 -[ "$name" ] || { [ -s $_git/refs/heads/origin ] && name=origin; } +if [ -z "$name" ]; then + branch=$(readlink $_git/HEAD | sed 's@refs/heads/@@') + name=$(cat $_git/branches/$branch 2>/dev/null) +fi [ "$name" ] || die "where to pull from?" uri=$(cat "$_git/branches/$name" 2>/dev/null) || die "unknown branch: $name" +[ -e "$_git/branches/$uri" ] && die "local branches cannot pull" + rembranch=master if echo "$uri" | grep -q '#'; then rembranch=$(echo $uri | cut -d '#' -f 2) - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.htmlReceived on Thu Jun 02 20:18:53 2005
This archive was generated by hypermail 2.1.8 : 2005-06-02 20:18:53 EST