return 0;
}
+static int should_setup_rebase(const struct tracking *tracking)
+{
+ switch (autorebase) {
+ case AUTOREBASE_NEVER:
+ return 0;
+ case AUTOREBASE_LOCAL:
+ return tracking->remote == NULL;
+ case AUTOREBASE_REMOTE:
+ return tracking->remote != NULL;
+ case AUTOREBASE_ALWAYS:
+ return 1;
+ }
+ return 0;
+}
+
/*
* This is called when new_ref is branched off of orig_ref, and tries
* to infer the settings for branch.<new_ref>.{remote,merge} from the
git_config_set(key, tracking.remote ? tracking.remote : ".");
sprintf(key, "branch.%s.merge", new_ref);
git_config_set(key, tracking.src ? tracking.src : orig_ref);
- free(tracking.src);
printf("Branch %s set up to track %s branch %s.\n", new_ref,
tracking.remote ? "remote" : "local", orig_ref);
+ if (should_setup_rebase(&tracking)) {
+ sprintf(key, "branch.%s.rebase", new_ref);
+ git_config_set(key, "true");
+ printf("This branch will rebase on pull.\n");
+ }
+ free(tracking.src);
return 0;
}
struct ref_lock *lock;
struct commit *commit;
unsigned char sha1[20];
- char *real_ref, ref[PATH_MAX], msg[PATH_MAX + 20];
+ char *real_ref, msg[PATH_MAX + 20];
+ struct strbuf ref = STRBUF_INIT;
int forcing = 0;
+ int len;
- snprintf(ref, sizeof ref, "refs/heads/%s", name);
- if (check_ref_format(ref))
+ len = strlen(name);
+ if (interpret_nth_last_branch(name, &ref) != len) {
+ strbuf_reset(&ref);
+ strbuf_add(&ref, name, len);
+ }
+ strbuf_splice(&ref, 0, 0, "refs/heads/", 11);
+
+ if (check_ref_format(ref.buf))
die("'%s' is not a valid branch name.", name);
- if (resolve_ref(ref, sha1, 1, NULL)) {
+ if (resolve_ref(ref.buf, sha1, 1, NULL)) {
if (!force)
die("A branch named '%s' already exists.", name);
else if (!is_bare_repository() && !strcmp(head, name))
die("Cannot setup tracking information; starting point is not a branch.");
break;
case 1:
- /* Unique completion -- good */
+ /* Unique completion -- good, only if it is a real ref */
+ if (track == BRANCH_TRACK_EXPLICIT && !strcmp(real_ref, "HEAD"))
+ die("Cannot setup tracking information; starting point is not a branch.");
break;
default:
die("Ambiguous object name: '%s'.", start_name);
die("Not a valid branch point: '%s'.", start_name);
hashcpy(sha1, commit->object.sha1);
- lock = lock_any_ref_for_update(ref, NULL, 0);
+ lock = lock_any_ref_for_update(ref.buf, NULL, 0);
if (!lock)
die("Failed to lock ref for update: %s.", strerror(errno));
if (write_ref_sha1(lock, sha1, msg) < 0)
die("Failed to write ref: %s.", strerror(errno));
+ strbuf_release(&ref);
free(real_ref);
}
void remove_branch_state(void)
{
unlink(git_path("MERGE_HEAD"));
- unlink(git_path("rr-cache/MERGE_RR"));
+ unlink(git_path("MERGE_RR"));
unlink(git_path("MERGE_MSG"));
+ unlink(git_path("MERGE_MODE"));
unlink(git_path("SQUASH_MSG"));
}