From: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
To: git@vger.kernel.org
Subject: [PATCH/RFC] Convenient support of remote branches in git-checkout
Date: Tue, 7 Nov 2006 00:26:16 +0100 [thread overview]
Message-ID: <200611070026.16425.Josef.Weidendorfer@gmx.de> (raw)
- When requested to checkout read-only remote branches,
we try to create a new local development branch with same name.
- When we branch off a remote branch, set up default merge source.
---
This patch does the sensible thing when the user requests to
check-out a remote read-only branch (eg. origin/master).
It also automatically sets up the default merge source (with remote
entry) for a new branch.
Example to hack on git's next branch:
git-clone --use-separate-remote http://www.kernel.org/pub/scm/git/git.git
cd git
git-checkout origin/next
<hack on next>
git pull (to merge patches from remote 'next')
The checkout creates local branch 'master' to checkout read-only remote branch
'remotes/origin/master'. Additionally, it sets up 'remotes/origin/master' from
remote repository 'origin' as default merge source for the new development branch.
Missing:
- "git branch -D <branch>" should remove remote branch attributes like
"remote" and "merge"
- As "git-clone" already sets up a local development branch "master", it also
should set up a default merge source for it
Josef
git-checkout.sh | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index 119bca1..63b622e 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -12,6 +12,8 @@ force=
branch=
newbranch=
newbranch_log=
+remote=
+remotebranch=
merge=
while [ "$#" != "0" ]; do
arg="$1"
@@ -55,6 +57,11 @@ while [ "$#" != "0" ]; do
then
branch="$arg"
fi
+ if git-show-ref --verify --quiet -- "refs/remotes/$arg"
+ then
+ remote=$(echo $arg | sed -ne 's!/.*$!!p')
+ remotebranch=$(echo $arg | sed -e 's!^.*/!!')
+ fi
elif rev=$(git-rev-parse --verify "$arg^{tree}" 2>/dev/null)
then
# checking out selected paths from a tree-ish.
@@ -77,6 +84,20 @@ while [ "$#" != "0" ]; do
esac
done
+# Create a new local branch when checking out remote read-only branch
+if test -z "$newbranch" -a ! -z "$remotebranch"
+then
+ newbranch=$remotebranch
+ if git-show-ref --verify --quiet -- "refs/heads/$newbranch"
+ then
+ echo "Proposed new branch '$newbranch' to checkout read-only remote branch 'remotes/$remote/$remotebranch' exists!"
+ echo "To checkout, specify a new branch name with -b"
+ exit 1
+ fi
+ echo "Creating local branch '$newbranch' to checkout read-only remote branch 'remotes/$remote/$remotebranch'."
+fi
+
+
# The behaviour of the command with and without explicit path
# parameters is quite different.
#
@@ -211,6 +232,14 @@ if [ "$?" -eq 0 ]; then
touch "$GIT_DIR/logs/refs/heads/$newbranch"
fi
git-update-ref -m "checkout: Created from $new_name" "refs/heads/$newbranch" $new || exit
+
+ if test '' != "$remote"
+ then
+ echo "Using 'remotes/$remote/$remotebranch' from remote repository '$remote' as default merge source."
+ git-repo-config branch."$newbranch".remote "$remote"
+ git-repo-config branch."$newbranch".merge "remotes/$remote/$remotebranch"
+ fi
+
branch="$newbranch"
fi
[ "$branch" ] &&
--
1.4.3.rc2.gf8ffb
next reply other threads:[~2006-11-06 23:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-06 23:26 Josef Weidendorfer [this message]
2006-11-06 23:30 ` [PATCH/RFC] Convenient support of remote branches in git-checkout Josef Weidendorfer
2006-11-07 0:13 ` Junio C Hamano
2006-11-07 1:25 ` Josef Weidendorfer
2006-11-07 2:03 ` Junio C Hamano
2006-11-07 2:08 ` Junio C Hamano
2006-11-07 10:18 ` Josef Weidendorfer
2006-11-07 2:27 ` Junio C Hamano
2006-11-07 10:28 ` Josef Weidendorfer
2006-11-07 6:54 ` Karl Hasselström
2006-11-07 10:53 ` Josef Weidendorfer
2006-11-07 13:56 ` Karl Hasselström
2006-11-07 17:04 ` Josef Weidendorfer
2006-11-07 7:07 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200611070026.16425.Josef.Weidendorfer@gmx.de \
--to=josef.weidendorfer@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox