From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>
Subject: [RFC PATCH 2/2] new --rebase option to set branch.*.rebase for new branches
Date: Fri, 15 Feb 2008 22:45:57 -0500 [thread overview]
Message-ID: <1203133557-50013-2-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <1203133557-50013-1-git-send-email-jaysoffian@gmail.com>
Add a --rebase option to git-branch and git-checkout. If given, it
implies --track but additionally sets branch.<newbranch>.rebase to true.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin-branch.c | 18 ++++++++++++++----
git-checkout.sh | 11 ++++++++---
2 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/builtin-branch.c b/builtin-branch.c
index 94ab195..1404d8b 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -393,7 +393,7 @@ static int find_tracked_branch(struct remote *remote, void *priv)
* to infer the settings for branch.<new_ref>.{remote,merge} from the
* config.
*/
-static int setup_tracking(const char *new_ref, const char *orig_ref)
+static int setup_tracking(const char *new_ref, const char *orig_ref, int rebase)
{
char key[1024];
struct tracking tracking;
@@ -407,6 +407,10 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)
git_config_set(key, ".");
sprintf(key, "branch.%s.merge", new_ref);
git_config_set(key, orig_ref);
+ if (rebase) {
+ sprintf(key, "branch.%s.rebase", new_ref);
+ git_config_set(key, "true");
+ }
printf("Branch %s set up to track local branch %s.\n",
new_ref, orig_ref);
return 0;
@@ -428,6 +432,10 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)
sprintf(key, "branch.%s.merge", new_ref);
git_config_set(key, tracking.src);
free(tracking.src);
+ if (rebase) {
+ sprintf(key, "branch.%s.rebase", new_ref);
+ git_config_set(key, "true");
+ }
printf("Branch %s set up to track remote branch %s.\n",
new_ref, orig_ref);
}
@@ -436,7 +444,7 @@ static int setup_tracking(const char *new_ref, const char *orig_ref)
}
static void create_branch(const char *name, const char *start_name,
- int force, int reflog, int track)
+ int force, int reflog, int track, int rebase)
{
struct ref_lock *lock;
struct commit *commit;
@@ -495,7 +503,7 @@ static void create_branch(const char *name, const char *start_name,
automatically merges from there. So far, this is only done for
remotes registered via .git/config. */
if (real_ref && track)
- setup_tracking(name, real_ref);
+ setup_tracking(name, real_ref, rebase);
if (write_ref_sha1(lock, sha1, msg) < 0)
die("Failed to write ref: %s.", strerror(errno));
@@ -566,12 +574,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
int reflog = 0, track;
int kinds = REF_LOCAL_BRANCH;
+ int rebase = 0;
struct commit_list *with_commit = NULL;
struct option options[] = {
OPT_GROUP("Generic options"),
OPT__VERBOSE(&verbose),
OPT_BOOLEAN( 0 , "track", &track, "set up tracking mode (see git-pull(1))"),
+ OPT_BOOLEAN( 0 , "rebase", &rebase, "set up branch to rebase (see git-pull(1))"),
OPT_BOOLEAN( 0 , "color", &branch_use_color, "use colored output"),
OPT_SET_INT('r', NULL, &kinds, "act on remote-tracking branches",
REF_REMOTE_BRANCH),
@@ -625,7 +635,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
rename_branch(argv[0], argv[1], rename > 1);
else if (argc <= 2)
create_branch(argv[0], (argc == 2) ? argv[1] : head,
- force_create, reflog, track);
+ force_create, reflog, track, rebase);
else
usage_with_options(builtin_branch_usage, options);
diff --git a/git-checkout.sh b/git-checkout.sh
index bd74d70..569e29c 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -7,6 +7,7 @@ git-checkout [options] [<branch>] [<paths>...]
b= create a new branch started at <branch>
l create the new branch's reflog
track arrange that the new branch tracks the remote branch
+rebase arrange that the new branch rebases
f proceed even if the index or working tree is not HEAD
m merge local modifications into the new branch
q,quiet be quiet
@@ -23,6 +24,7 @@ new_name=
force=
branch=
track=
+rebase=
newbranch=
newbranch_log=
merge=
@@ -49,6 +51,9 @@ while test $# != 0; do
--track|--no-track)
track="$1"
;;
+ --rebase)
+ rebase="$1"
+ ;;
-f)
force=1
;;
@@ -92,9 +97,9 @@ then
fi
[ "$1" = "--" ] && shift
-case "$newbranch,$track" in
+case "$newbranch,$track,$rebase" in
,--*)
- die "git checkout: --track and --no-track require -b"
+ die "git checkout: --track, --no-track and --rebase require -b"
esac
case "$force$merge" in
@@ -261,7 +266,7 @@ fi
#
if [ "$?" -eq 0 ]; then
if [ "$newbranch" ]; then
- git branch $track $newbranch_log "$newbranch" "$new_name" || exit
+ git branch $track $rebase $newbranch_log "$newbranch" "$new_name" || exit
branch="$newbranch"
fi
if test -n "$branch"
--
1.5.4.1.1281.g75df
next prev parent reply other threads:[~2008-02-16 3:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-16 3:45 [RFC PATCH 1/2] git-branch: allow --track to work w/local branches Jay Soffian
2008-02-16 3:45 ` Jay Soffian [this message]
2008-02-16 5:10 ` Junio C Hamano
2008-02-16 7:07 ` Jay Soffian
2008-02-16 11:45 ` Johannes Schindelin
2008-02-17 18:05 ` Jay Soffian
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=1203133557-50013-2-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).