Skip to content

Commit ffd4df6

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#4151 from novalis/dturner/rebase-submodule-untracked
rebase: ignore untracked files in submodules
2 parents b31b236 + 2270ca9 commit ffd4df6

34 files changed

+191
-1
lines changed

src/rebase.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,9 @@ static int rebase_ensure_not_dirty(
546546
}
547547

548548
if (check_workdir) {
549-
if ((error = git_diff_index_to_workdir(&diff, repo, index, NULL)) < 0)
549+
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
550+
diff_opts.ignore_submodules = GIT_SUBMODULE_IGNORE_UNTRACKED;
551+
if ((error = git_diff_index_to_workdir(&diff, repo, index, &diff_opts)) < 0)
550552
goto done;
551553

552554
if (git_diff_num_deltas(diff) > 0) {

tests/rebase/submodule.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "clar_libgit2.h"
2+
#include "git2/checkout.h"
3+
#include "git2/rebase.h"
4+
#include "posix.h"
5+
#include "signature.h"
6+
7+
#include <fcntl.h>
8+
9+
static git_repository *repo;
10+
static git_signature *signature;
11+
12+
// Fixture setup and teardown
13+
void test_rebase_submodule__initialize(void)
14+
{
15+
repo = cl_git_sandbox_init("rebase-submodule");
16+
cl_git_pass(git_signature_new(&signature,
17+
"Rebaser", "rebaser@rebaser.rb", 1405694510, 0));
18+
}
19+
20+
void test_rebase_submodule__cleanup(void)
21+
{
22+
git_signature_free(signature);
23+
cl_git_sandbox_cleanup();
24+
}
25+
26+
void test_rebase_submodule__init_untracked(void)
27+
{
28+
git_rebase *rebase;
29+
git_reference *branch_ref, *upstream_ref;
30+
git_annotated_commit *branch_head, *upstream_head;
31+
git_buf untracked_path = GIT_BUF_INIT;
32+
FILE *fp;
33+
git_submodule *submodule;
34+
git_config *config;
35+
36+
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
37+
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
38+
39+
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
40+
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
41+
42+
git_repository_config(&config, repo);
43+
44+
cl_git_pass(git_config_set_string(config, "submodule.my-submodule.url", git_repository_path(repo)));
45+
46+
git_config_free(config);
47+
48+
cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule"));
49+
cl_git_pass(git_submodule_update(submodule, 1, NULL));
50+
51+
git_buf_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
52+
fp = fopen(git_buf_cstr(&untracked_path), "w");
53+
fprintf(fp, "An untracked file in a submodule should not block a rebase\n");
54+
fclose(fp);
55+
git_buf_free(&untracked_path);
56+
57+
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
58+
59+
git_submodule_free(submodule);
60+
git_annotated_commit_free(branch_head);
61+
git_annotated_commit_free(upstream_head);
62+
git_reference_free(branch_ref);
63+
git_reference_free(upstream_ref);
64+
git_rebase_free(rebase);
65+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "my-submodule"]
2+
path = my-submodule
3+
url = bogus
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5fdf086684daae0a8bc61a81afe178edc1e556e7
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
[branch "asparagus"]
7+
rebase = true
8+
[branch "master"]
9+
rebase = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
681 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
c64ea52df5b31efd7b73769418dc9e25b8803d25 refs/heads/asparagus
2+
c64ea52df5b31efd7b73769418dc9e25b8803d25 refs/remotes/origin/HEAD
3+
c64ea52df5b31efd7b73769418dc9e25b8803d25 refs/remotes/origin/asparagus
4+
02a35db3f24db554b757b3009bc782784267c743 refs/remotes/origin/master

0 commit comments

Comments
 (0)