rebase: ignore untracked files in submodules

An untracked file in a submodule should not prevent a rebase from
starting.  Even if the submodule's SHA is changed, and that file would
conflict with a new tracked file, it's still OK to start the rebase
and discover the conflict later.

Signed-off-by: David Turner <dturner@twosigma.com>
This commit is contained in:
David Turner 2017-03-03 13:27:47 -05:00
parent 467185ff13
commit 2270ca9f8f
34 changed files with 69 additions and 1 deletions

View File

@ -546,7 +546,9 @@ static int rebase_ensure_not_dirty(
}
if (check_workdir) {
if ((error = git_diff_index_to_workdir(&diff, repo, index, NULL)) < 0)
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
diff_opts.ignore_submodules = GIT_SUBMODULE_IGNORE_UNTRACKED;
if ((error = git_diff_index_to_workdir(&diff, repo, index, &diff_opts)) < 0)
goto done;
if (git_diff_num_deltas(diff) > 0) {

65
tests/rebase/submodule.c Normal file
View File

@ -0,0 +1,65 @@
#include "clar_libgit2.h"
#include "git2/checkout.h"
#include "git2/rebase.h"
#include "posix.h"
#include "signature.h"
#include <fcntl.h>
static git_repository *repo;
static git_signature *signature;
// Fixture setup and teardown
void test_rebase_submodule__initialize(void)
{
repo = cl_git_sandbox_init("rebase-submodule");
cl_git_pass(git_signature_new(&signature,
"Rebaser", "rebaser@rebaser.rb", 1405694510, 0));
}
void test_rebase_submodule__cleanup(void)
{
git_signature_free(signature);
cl_git_sandbox_cleanup();
}
void test_rebase_submodule__init_untracked(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_buf untracked_path = GIT_BUF_INIT;
FILE *fp;
git_submodule *submodule;
git_config *config;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
cl_git_pass(git_reference_lookup(&upstream_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(&upstream_head, repo, upstream_ref));
git_repository_config(&config, repo);
cl_git_pass(git_config_set_string(config, "submodule.my-submodule.url", git_repository_path(repo)));
git_config_free(config);
cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule"));
cl_git_pass(git_submodule_update(submodule, 1, NULL));
git_buf_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
fp = fopen(git_buf_cstr(&untracked_path), "w");
fprintf(fp, "An untracked file in a submodule should not block a rebase\n");
fclose(fp);
git_buf_free(&untracked_path);
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
git_submodule_free(submodule);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1 @@
Subproject commit efad0b11c47cb2f0220cbd6f5b0f93bb99064b00

Binary file not shown.

Binary file not shown.