summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/iterator.c7
-rw-r--r--src/rebase.c73
-rw-r--r--src/stransport_stream.c6
-rw-r--r--src/tag.c10
-rw-r--r--src/transports/smart.c2
-rw-r--r--tests/object/tag/read.c37
-rw-r--r--tests/online/clone.c4
-rw-r--r--tests/rebase/abort.c70
-rw-r--r--tests/rebase/merge.c50
9 files changed, 217 insertions, 42 deletions
diff --git a/src/iterator.c b/src/iterator.c
index ec44aac4c..87e0d53d4 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -206,8 +206,7 @@ GIT_INLINE(bool) iterator_has_started(
return false;
}
-GIT_INLINE(bool) iterator_has_ended(
- git_iterator *iter, const char *path, bool is_submodule)
+GIT_INLINE(bool) iterator_has_ended(git_iterator *iter, const char *path)
{
if (iter->end == NULL)
return false;
@@ -797,7 +796,7 @@ static int tree_iterator_advance(const git_index_entry **out, git_iterator *i)
continue;
/* if this path is after our end, stop */
- if (iterator_has_ended(&iter->base, iter->entry_path.ptr, false)) {
+ if (iterator_has_ended(&iter->base, iter->entry_path.ptr)) {
error = GIT_ITEROVER;
break;
}
@@ -2034,7 +2033,7 @@ static int index_iterator_advance(
continue;
}
- if (iterator_has_ended(&iter->base, entry->path, is_submodule)) {
+ if (iterator_has_ended(&iter->base, entry->path)) {
error = GIT_ITEROVER;
break;
}
diff --git a/src/rebase.c b/src/rebase.c
index bcad9b7cd..93a91545d 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -472,6 +472,7 @@ done:
static int rebase_setupfiles(git_rebase *rebase)
{
char onto[GIT_OID_HEXSZ], orig_head[GIT_OID_HEXSZ];
+ const char *orig_head_name;
git_oid_fmt(onto, &rebase->onto_id);
git_oid_fmt(orig_head, &rebase->orig_head_id);
@@ -481,8 +482,11 @@ static int rebase_setupfiles(git_rebase *rebase)
return -1;
}
+ orig_head_name = rebase->head_detached ? ORIG_DETACHED_HEAD :
+ rebase->orig_head_name;
+
if (git_repository__set_orig_head(rebase->repo, &rebase->orig_head_id) < 0 ||
- rebase_setupfile(rebase, HEAD_NAME_FILE, -1, "%s\n", rebase->orig_head_name) < 0 ||
+ rebase_setupfile(rebase, HEAD_NAME_FILE, -1, "%s\n", orig_head_name) < 0 ||
rebase_setupfile(rebase, ONTO_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, onto) < 0 ||
rebase_setupfile(rebase, ORIG_HEAD_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, orig_head) < 0 ||
rebase_setupfile(rebase, QUIET_FILE, -1, rebase->quiet ? "t\n" : "\n") < 0)
@@ -626,8 +630,12 @@ static int rebase_init_merge(
rebase->state_path = git_buf_detach(&state_path);
GITERR_CHECK_ALLOC(rebase->state_path);
- rebase->orig_head_name = git__strdup(branch->ref_name ? branch->ref_name : ORIG_DETACHED_HEAD);
- GITERR_CHECK_ALLOC(rebase->orig_head_name);
+ if (branch->ref_name) {
+ rebase->orig_head_name = git__strdup(branch->ref_name);
+ GITERR_CHECK_ALLOC(rebase->orig_head_name);
+ } else {
+ rebase->head_detached = 1;
+ }
rebase->onto_name = git__strdup(rebase_onto_name(onto));
GITERR_CHECK_ALLOC(rebase->onto_name);
@@ -1254,42 +1262,33 @@ done:
return error;
}
-int git_rebase_finish(
- git_rebase *rebase,
- const git_signature *signature)
+static int return_to_orig_head(git_rebase *rebase)
{
git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL;
git_commit *terminal_commit = NULL;
git_buf branch_msg = GIT_BUF_INIT, head_msg = GIT_BUF_INIT;
char onto[GIT_OID_HEXSZ];
- int error;
-
- assert(rebase);
-
- if (rebase->inmemory)
- return 0;
+ int error = 0;
git_oid_fmt(onto, &rebase->onto_id);
- if ((error = git_buf_printf(&branch_msg, "rebase finished: %s onto %.*s",
- rebase->orig_head_name, GIT_OID_HEXSZ, onto)) < 0 ||
- (error = git_buf_printf(&head_msg, "rebase finished: returning to %s",
- rebase->orig_head_name)) < 0 ||
- (error = git_repository_head(&terminal_ref, rebase->repo)) < 0 ||
+ if ((error = git_buf_printf(&branch_msg,
+ "rebase finished: %s onto %.*s",
+ rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 &&
+ (error = git_buf_printf(&head_msg,
+ "rebase finished: returning to %s",
+ rebase->orig_head_name)) == 0 &&
+ (error = git_repository_head(&terminal_ref, rebase->repo)) == 0 &&
(error = git_reference_peel((git_object **)&terminal_commit,
- terminal_ref, GIT_OBJ_COMMIT)) < 0 ||
+ terminal_ref, GIT_OBJ_COMMIT)) == 0 &&
(error = git_reference_create_matching(&branch_ref,
- rebase->repo, rebase->orig_head_name, git_commit_id(terminal_commit), 1,
- &rebase->orig_head_id, branch_msg.ptr)) < 0 ||
- (error = git_reference_symbolic_create(&head_ref,
+ rebase->repo, rebase->orig_head_name,
+ git_commit_id(terminal_commit), 1,
+ &rebase->orig_head_id, branch_msg.ptr)) == 0)
+ error = git_reference_symbolic_create(&head_ref,
rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1,
- head_msg.ptr)) < 0 ||
- (error = rebase_copy_notes(rebase, signature)) < 0)
- goto done;
-
- error = rebase_cleanup(rebase);
+ head_msg.ptr);
-done:
git_buf_free(&head_msg);
git_buf_free(&branch_msg);
git_commit_free(terminal_commit);
@@ -1300,6 +1299,26 @@ done:
return error;
}
+int git_rebase_finish(
+ git_rebase *rebase,
+ const git_signature *signature)
+{
+ int error = 0;
+
+ assert(rebase);
+
+ if (rebase->inmemory)
+ return 0;
+
+ if (!rebase->head_detached)
+ error = return_to_orig_head(rebase);
+
+ if (error == 0 && (error = rebase_copy_notes(rebase, signature)) == 0)
+ error = rebase_cleanup(rebase);
+
+ return error;
+}
+
size_t git_rebase_operation_entrycount(git_rebase *rebase)
{
assert(rebase);
diff --git a/src/stransport_stream.c b/src/stransport_stream.c
index 33b6c5c38..8d28b3ceb 100644
--- a/src/stransport_stream.c
+++ b/src/stransport_stream.c
@@ -116,11 +116,13 @@ int stransport_certificate(git_cert **out, git_stream *stream)
return 0;
}
-int stransport_set_proxy(git_stream *stream, const char *proxy)
+int stransport_set_proxy(
+ git_stream *stream,
+ const git_proxy_options *proxy_opts)
{
stransport_stream *st = (stransport_stream *) stream;
- return git_stream_set_proxy(st->io, proxy);
+ return git_stream_set_proxy(st->io, proxy_opts);
}
/*
diff --git a/src/tag.c b/src/tag.c
index c4bce1f22..fe840fe82 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -137,8 +137,14 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
tag->message = NULL;
if (buffer < buffer_end) {
- if( *buffer != '\n' )
- return tag_error("No new line before message");
+ /* If we're not at the end of the header, search for it */
+ if( *buffer != '\n' ) {
+ search = strstr(buffer, "\n\n");
+ if (search)
+ buffer = search + 1;
+ else
+ return tag_error("tag contains no message");
+ }
text_len = buffer_end - ++buffer;
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 11b4b09a4..7a35c39d8 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -444,7 +444,7 @@ static void git_smart__free(git_transport *transport)
git_pkt_free(p);
git_vector_free(refs);
- git__free(t->proxy.url);
+ git__free((char *)t->proxy.url);
git_strarray_free(&t->custom_headers);
diff --git a/tests/object/tag/read.c b/tests/object/tag/read.c
index c9787a413..8f28afd54 100644
--- a/tests/object/tag/read.c
+++ b/tests/object/tag/read.c
@@ -140,3 +140,40 @@ void test_object_tag_read__without_tagger_nor_message(void)
git_tag_free(tag);
git_repository_free(repo);
}
+
+static const char *silly_tag = "object c054ccaefbf2da31c3b19178f9e3ef20a3867924\n\
+type commit\n\
+tag v1_0_1\n\
+tagger Jamis Buck <jamis@37signals.com> 1107717917\n\
+diff --git a/lib/sqlite3/version.rb b/lib/sqlite3/version.rb\n\
+index 0b3bf69..4ee8fc2 100644\n\
+--- a/lib/sqlite3/version.rb\n\
++++ b/lib/sqlite3/version.rb\n\
+@@ -36,7 +36,7 @@ module SQLite3\n\
+ \n\
+ MAJOR = 1\n\
+ MINOR = 0\n\
+- TINY = 0\n\
++ TINY = 1\n\
+ \n\
+ STRING = [ MAJOR, MINOR, TINY ].join( \".\" )\n\
+ \n\
+ -0600\n\
+\n\
+v1_0_1 release\n";
+
+void test_object_tag_read__extra_header_fields(void)
+{
+ git_tag *tag;
+ git_odb *odb;
+ git_oid id;
+
+ cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
+
+ cl_git_pass(git_odb_write(&id, odb, silly_tag, strlen(silly_tag), GIT_OBJ_TAG));
+ cl_git_pass(git_tag_lookup(&tag, g_repo, &id));
+
+ cl_assert_equal_s("v1_0_1 release\n", git_tag_message(tag));
+
+ git_tag_free(tag);
+}
diff --git a/tests/online/clone.c b/tests/online/clone.c
index 0fc8d4271..04fd22d45 100644
--- a/tests/online/clone.c
+++ b/tests/online/clone.c
@@ -666,8 +666,10 @@ void test_online_clone__start_with_http(void)
static int called_proxy_creds;
static int proxy_creds(git_cred **out, const char *url, const char *username, unsigned int allowed, void *payload)
{
- GIT_UNUSED(payload);
+ GIT_UNUSED(url);
GIT_UNUSED(username);
+ GIT_UNUSED(allowed);
+ GIT_UNUSED(payload);
called_proxy_creds = 1;
return git_cred_userpass_plaintext_new(out, _remote_proxy_user, _remote_proxy_pass);
diff --git a/tests/rebase/abort.c b/tests/rebase/abort.c
index 4cf14ddce..70529521f 100644
--- a/tests/rebase/abort.c
+++ b/tests/rebase/abort.c
@@ -19,17 +19,15 @@ void test_rebase_abort__cleanup(void)
cl_git_sandbox_cleanup();
}
-static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
+static void ensure_aborted(
+ git_annotated_commit *branch,
+ git_annotated_commit *onto)
{
- git_rebase *rebase;
git_reference *head_ref, *branch_ref = NULL;
git_status_list *statuslist;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
- cl_git_pass(git_rebase_open(&rebase, repo, NULL));
- cl_git_pass(git_rebase_abort(rebase));
-
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
/* Make sure the refs are updated appropriately */
@@ -58,6 +56,18 @@ static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto)
git_reflog_free(reflog);
git_reference_free(head_ref);
git_reference_free(branch_ref);
+}
+
+static void test_abort(
+ git_annotated_commit *branch, git_annotated_commit *onto)
+{
+ git_rebase *rebase;
+
+ cl_git_pass(git_rebase_open(&rebase, repo, NULL));
+ cl_git_pass(git_rebase_abort(rebase));
+
+ ensure_aborted(branch, onto);
+
git_rebase_free(rebase);
}
@@ -86,6 +96,32 @@ void test_rebase_abort__merge(void)
git_rebase_free(rebase);
}
+void test_rebase_abort__merge_immediately_after_init(void)
+{
+ git_rebase *rebase;
+ git_reference *branch_ref, *onto_ref;
+ git_annotated_commit *branch_head, *onto_head;
+
+ cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
+ cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
+
+ cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
+ cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
+
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+ cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
+
+ cl_git_pass(git_rebase_abort(rebase));
+ ensure_aborted(branch_head, onto_head);
+
+ git_annotated_commit_free(branch_head);
+ git_annotated_commit_free(onto_head);
+
+ git_reference_free(branch_ref);
+ git_reference_free(onto_ref);
+ git_rebase_free(rebase);
+}
+
void test_rebase_abort__merge_by_id(void)
{
git_rebase *rebase;
@@ -109,6 +145,30 @@ void test_rebase_abort__merge_by_id(void)
git_rebase_free(rebase);
}
+void test_rebase_abort__merge_by_id_immediately_after_init(void)
+{
+ git_rebase *rebase;
+ git_oid branch_id, onto_id;
+ git_annotated_commit *branch_head, *onto_head;
+
+ cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
+ cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
+
+ cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
+ cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
+
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
+ cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
+
+ cl_git_pass(git_rebase_abort(rebase));
+ ensure_aborted(branch_head, onto_head);
+
+ git_annotated_commit_free(branch_head);
+ git_annotated_commit_free(onto_head);
+
+ git_rebase_free(rebase);
+}
+
void test_rebase_abort__detached_head(void)
{
git_rebase *rebase;
diff --git a/tests/rebase/merge.c b/tests/rebase/merge.c
index d090e02e8..2d6df369e 100644
--- a/tests/rebase/merge.c
+++ b/tests/rebase/merge.c
@@ -475,6 +475,56 @@ void test_rebase_merge__finish(void)
git_rebase_free(rebase);
}
+void test_rebase_merge__finish_with_ids(void)
+{
+ git_rebase *rebase;
+ git_reference *head_ref;
+ git_oid branch_id, upstream_id;
+ git_annotated_commit *branch_head, *upstream_head;
+ git_rebase_operation *rebase_operation;
+ git_oid commit_id;
+ git_reflog *reflog;
+ const git_reflog_entry *reflog_entry;
+ int error;
+
+ cl_git_pass(git_oid_fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f"));
+ cl_git_pass(git_oid_fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864"));
+
+ cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
+ cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id));
+
+ cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
+
+ cl_git_pass(git_rebase_next(&rebase_operation, rebase));
+ cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
+ NULL, NULL));
+
+ cl_git_fail(error = git_rebase_next(&rebase_operation, rebase));
+ cl_assert_equal_i(GIT_ITEROVER, error);
+
+ cl_git_pass(git_rebase_finish(rebase, signature));
+
+ cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
+
+ cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
+ cl_assert_equal_i(GIT_REF_OID, git_reference_type(head_ref));
+ cl_assert_equal_oid(&commit_id, git_reference_target(head_ref));
+
+ /* reflogs are not updated as if we were operating on proper
+ * branches. check that the last reflog entry is the rebase.
+ */
+ cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
+ cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
+ cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
+ cl_assert_equal_s("rebase: Modification 3 to gravy", git_reflog_entry_message(reflog_entry));
+ git_reflog_free(reflog);
+
+ git_annotated_commit_free(branch_head);
+ git_annotated_commit_free(upstream_head);
+ git_reference_free(head_ref);
+ git_rebase_free(rebase);
+}
+
static void test_copy_note(
const git_rebase_options *opts,
bool should_exist)