summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/git2/index.h4
-rw-r--r--src/checkout.c2
-rw-r--r--src/diff.c4
-rw-r--r--src/revwalk.c52
-rw-r--r--src/revwalk.h3
-rw-r--r--tests/revwalk/basic.c79
-rw-r--r--tests/status/status_helpers.h10
-rw-r--r--tests/status/submodules.c197
8 files changed, 282 insertions, 69 deletions
diff --git a/include/git2/index.h b/include/git2/index.h
index ae919e133..9a7ad28a6 100644
--- a/include/git2/index.h
+++ b/include/git2/index.h
@@ -158,8 +158,8 @@ typedef enum {
* to back it.
*
* Since there is no ODB or working directory behind this index,
- * any Index methods which rely on these (e.g. index_add) will
- * fail with the GIT_EBAREINDEX error code.
+ * any Index methods which rely on these (e.g. index_add_bypath)
+ * will fail with the GIT_ERROR error code.
*
* If you need to access the index of an actual repository,
* use the `git_repository_index` wrapper.
diff --git a/src/checkout.c b/src/checkout.c
index 468c8dc6e..141fc1331 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -339,7 +339,7 @@ static bool submodule_is_config_only(
git_submodule_free(sm);
- return false;
+ return rval;
}
static int checkout_action_with_wd(
diff --git a/src/diff.c b/src/diff.c
index 25c5937e6..484273f4a 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -880,8 +880,10 @@ static int handle_unmatched_new_item(
git_buf *full = NULL;
if (git_iterator_current_workdir_path(&full, info->new_iter) < 0)
return -1;
- if (full && git_path_contains_dir(full, DOT_GIT))
+ if (full && git_path_contains(full, DOT_GIT)) {
+ /* TODO: warning if not a valid git repository */
recurse_into_dir = false;
+ }
}
/* still have to look into untracked directories to match core git -
diff --git a/src/revwalk.c b/src/revwalk.c
index f0109360b..7aedd1f44 100644
--- a/src/revwalk.c
+++ b/src/revwalk.c
@@ -39,8 +39,9 @@ git_commit_list_node *git_revwalk__commit_lookup(
return commit;
}
-static int mark_uninteresting(git_commit_list_node *commit)
+static int mark_uninteresting(git_revwalk *walk, git_commit_list_node *commit)
{
+ int error;
unsigned short i;
git_array_t(git_commit_list_node *) pending = GIT_ARRAY_INIT;
git_commit_list_node **tmp;
@@ -53,12 +54,8 @@ static int mark_uninteresting(git_commit_list_node *commit)
do {
commit->uninteresting = 1;
- /* This means we've reached a merge base, so there's no need to walk any more */
- if ((commit->flags & (RESULT | STALE)) == RESULT) {
- tmp = git_array_pop(pending);
- commit = tmp ? *tmp : NULL;
- continue;
- }
+ if ((error = git_commit_list_parse(walk, commit)) < 0)
+ return error;
for (i = 0; i < commit->out_degree; ++i)
if (!commit->parents[i]->uninteresting) {
@@ -84,7 +81,7 @@ static int process_commit(git_revwalk *walk, git_commit_list_node *commit, int h
if (!hide && walk->hide_cb)
hide = walk->hide_cb(&commit->oid, walk->hide_cb_payload);
- if (hide && mark_uninteresting(commit) < 0)
+ if (hide && mark_uninteresting(walk, commit) < 0)
return -1;
if (commit->seen)
@@ -95,7 +92,10 @@ static int process_commit(git_revwalk *walk, git_commit_list_node *commit, int h
if ((error = git_commit_list_parse(walk, commit)) < 0)
return error;
- return walk->enqueue(walk, commit);
+ if (!hide)
+ return walk->enqueue(walk, commit);
+
+ return 0;
}
static int process_commit_parents(git_revwalk *walk, git_commit_list_node *commit)
@@ -144,9 +144,6 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
if (commit == NULL)
return -1; /* error already reported by failed lookup */
- if (uninteresting)
- walk->did_hide = 1;
-
commit->uninteresting = uninteresting;
if (walk->one == NULL && !uninteresting) {
walk->one = commit;
@@ -298,15 +295,14 @@ static int revwalk_next_timesort(git_commit_list_node **object_out, git_revwalk
int error;
git_commit_list_node *next;
- while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) {
- if ((error = process_commit_parents(walk, next)) < 0)
- return error;
-
+ while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL)
if (!next->uninteresting) {
+ if ((error = process_commit_parents(walk, next)) < 0)
+ return error;
+
*object_out = next;
return 0;
}
- }
giterr_clear();
return GIT_ITEROVER;
@@ -317,15 +313,14 @@ static int revwalk_next_unsorted(git_commit_list_node **object_out, git_revwalk
int error;
git_commit_list_node *next;
- while ((next = git_commit_list_pop(&walk->iterator_rand)) != NULL) {
- if ((error = process_commit_parents(walk, next)) < 0)
- return error;
-
+ while ((next = git_commit_list_pop(&walk->iterator_rand)) != NULL)
if (!next->uninteresting) {
+ if ((error = process_commit_parents(walk, next)) < 0)
+ return error;
+
*object_out = next;
return 0;
}
- }
giterr_clear();
return GIT_ITEROVER;
@@ -380,7 +375,6 @@ static int prepare_walk(git_revwalk *walk)
int error;
unsigned int i;
git_commit_list_node *next, *two;
- git_commit_list *bases = NULL;
/*
* If walk->one is NULL, there were no positive references,
@@ -391,18 +385,6 @@ static int prepare_walk(git_revwalk *walk)
return GIT_ITEROVER;
}
- /*
- * If the user asked to hide commits, we need to figure out
- * what the merge bases are so we can know when we can stop
- * marking parents uninteresting.
- */
- if (walk->did_hide) {
- if (git_merge__bases_many(&bases, walk, walk->one, &walk->twos) < 0)
- return -1;
-
- git_commit_list_free(&bases);
- }
-
if (process_commit(walk, walk->one, walk->one->uninteresting) < 0)
return -1;
diff --git a/src/revwalk.h b/src/revwalk.h
index a0654f3e5..d81f97c01 100644
--- a/src/revwalk.h
+++ b/src/revwalk.h
@@ -32,8 +32,7 @@ struct git_revwalk {
int (*enqueue)(git_revwalk *, git_commit_list_node *);
unsigned walking:1,
- first_parent: 1,
- did_hide: 1;
+ first_parent: 1;
unsigned int sorting;
/* merge base calculation */
diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c
index 7e08c1840..b015db18b 100644
--- a/tests/revwalk/basic.c
+++ b/tests/revwalk/basic.c
@@ -160,7 +160,7 @@ void test_revwalk_basic__glob_heads(void)
}
/* git log --branches --oneline | wc -l => 14 */
- cl_assert(i == 14);
+ cl_assert_equal_i(i, 14);
}
void test_revwalk_basic__glob_heads_with_invalid(void)
@@ -194,7 +194,7 @@ void test_revwalk_basic__push_head(void)
}
/* git log HEAD --oneline | wc -l => 7 */
- cl_assert(i == 7);
+ cl_assert_equal_i(i, 7);
}
void test_revwalk_basic__push_head_hide_ref(void)
@@ -212,7 +212,7 @@ void test_revwalk_basic__push_head_hide_ref(void)
}
/* git log HEAD --oneline --not refs/heads/packed-test | wc -l => 4 */
- cl_assert(i == 4);
+ cl_assert_equal_i(i, 4);
}
void test_revwalk_basic__push_head_hide_ref_nobase(void)
@@ -230,7 +230,78 @@ void test_revwalk_basic__push_head_hide_ref_nobase(void)
}
/* git log HEAD --oneline --not refs/heads/packed | wc -l => 7 */
- cl_assert(i == 7);
+ cl_assert_equal_i(i, 7);
+}
+
+/*
+* $ git rev-list HEAD 5b5b02 ^refs/heads/packed-test
+* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+* be3563ae3f795b2b4353bcce3a527ad0a4f7f644
+* c47800c7266a2be04c571c04d5a6614691ea99bd
+* 9fd738e8f7967c078dceed8190330fc8648ee56a
+
+* $ git log HEAD 5b5b02 --oneline --not refs/heads/packed-test | wc -l => 4
+* a65fedf
+* be3563a Merge branch 'br2'
+* c47800c branch commit one
+* 9fd738e a fourth commit
+*/
+void test_revwalk_basic__multiple_push_1(void)
+{
+ int i = 0;
+ git_oid oid;
+
+ revwalk_basic_setup_walk(NULL);
+
+ cl_git_pass(git_revwalk_push_head(_walk));
+
+ cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
+
+ cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
+ cl_git_pass(git_revwalk_push(_walk, &oid));
+
+ while (git_revwalk_next(&oid, _walk) == 0)
+ i++;
+
+ cl_assert_equal_i(i, 4);
+}
+
+/*
+* Difference between test_revwalk_basic__multiple_push_1 and
+* test_revwalk_basic__multiple_push_2 is in the order reference
+* refs/heads/packed-test and commit 5b5b02 are pushed.
+* revwalk should return same commits in both the tests.
+
+* $ git rev-list 5b5b02 HEAD ^refs/heads/packed-test
+* a65fedf39aefe402d3bb6e24df4d4f5fe4547750
+* be3563ae3f795b2b4353bcce3a527ad0a4f7f644
+* c47800c7266a2be04c571c04d5a6614691ea99bd
+* 9fd738e8f7967c078dceed8190330fc8648ee56a
+
+* $ git log 5b5b02 HEAD --oneline --not refs/heads/packed-test | wc -l => 4
+* a65fedf
+* be3563a Merge branch 'br2'
+* c47800c branch commit one
+* 9fd738e a fourth commit
+*/
+void test_revwalk_basic__multiple_push_2(void)
+{
+ int i = 0;
+ git_oid oid;
+
+ revwalk_basic_setup_walk(NULL);
+
+ cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"));
+ cl_git_pass(git_revwalk_push(_walk, &oid));
+
+ cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test"));
+
+ cl_git_pass(git_revwalk_push_head(_walk));
+
+ while (git_revwalk_next(&oid, _walk) == 0)
+ i++;
+
+ cl_assert_equal_i(i, 4);
}
void test_revwalk_basic__disallow_non_commit(void)
diff --git a/tests/status/status_helpers.h b/tests/status/status_helpers.h
index f1f009e02..242076cc9 100644
--- a/tests/status/status_helpers.h
+++ b/tests/status/status_helpers.h
@@ -8,9 +8,19 @@ typedef struct {
const unsigned int* expected_statuses;
const char** expected_paths;
int expected_entry_count;
+ const char *file;
+ int line;
bool debug;
} status_entry_counts;
+#define status_counts_init(counts, paths, statuses) do { \
+ memset(&(counts), 0, sizeof(counts)); \
+ (counts).expected_statuses = (statuses); \
+ (counts).expected_paths = (paths); \
+ (counts).file = __FILE__; \
+ (counts).line = __LINE__; \
+ } while (0)
+
/* cb_status__normal takes payload of "status_entry_counts *" */
extern int cb_status__normal(
diff --git a/tests/status/submodules.c b/tests/status/submodules.c
index 8575f9f2d..6d0d63a5f 100644
--- a/tests/status/submodules.c
+++ b/tests/status/submodules.c
@@ -72,8 +72,15 @@ static int cb_status__match(const char *p, unsigned int s, void *payload)
status_entry_counts *counts = payload;
int idx = counts->entry_count++;
- cl_assert_equal_s(counts->expected_paths[idx], p);
- cl_assert(counts->expected_statuses[idx] == s);
+ clar__assert_equal(
+ counts->file, counts->line,
+ "Status path mismatch", 1,
+ "%s", counts->expected_paths[idx], p);
+
+ clar__assert_equal(
+ counts->file, counts->line,
+ "Status code mismatch", 1,
+ "%o", counts->expected_statuses[idx], s);
return 0;
}
@@ -88,13 +95,9 @@ void test_status_submodules__1(void)
cl_assert(git_path_isdir("submodules/testrepo/.git"));
cl_assert(git_path_isfile("submodules/.gitmodules"));
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files;
- counts.expected_statuses = expected_status;
+ status_counts_init(counts, expected_files, expected_status);
- cl_git_pass(
- git_status_foreach(g_repo, cb_status__match, &counts)
- );
+ cl_git_pass( git_status_foreach(g_repo, cb_status__match, &counts) );
cl_assert_equal_i(6, counts.entry_count);
}
@@ -146,24 +149,19 @@ void test_status_submodules__moved_head(void)
/* first do a normal status, which should now include the submodule */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files_with_sub;
- counts.expected_statuses = expected_status_with_sub;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ status_counts_init(
+ counts, expected_files_with_sub, expected_status_with_sub);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(7, counts.entry_count);
/* try again with EXCLUDE_SUBMODULES which should skip it */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files;
- counts.expected_statuses = expected_status;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
+ status_counts_init(counts, expected_files, expected_status);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(6, counts.entry_count);
@@ -201,24 +199,19 @@ void test_status_submodules__dirty_workdir_only(void)
/* first do a normal status, which should now include the submodule */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files_with_sub;
- counts.expected_statuses = expected_status_with_sub;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS;
+ status_counts_init(
+ counts, expected_files_with_sub, expected_status_with_sub);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(7, counts.entry_count);
/* try again with EXCLUDE_SUBMODULES which should skip it */
- memset(&counts, 0, sizeof(counts));
- counts.expected_paths = expected_files;
- counts.expected_statuses = expected_status;
-
opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_EXCLUDE_SUBMODULES;
+ status_counts_init(counts, expected_files, expected_status);
cl_git_pass(
git_status_foreach_ext(g_repo, &opts, cb_status__match, &counts));
cl_assert_equal_i(6, counts.entry_count);
@@ -240,3 +233,159 @@ void test_status_submodules__uninitialized(void)
git_repository_free(cloned_repo);
cl_git_sandbox_cleanup();
}
+
+void test_status_submodules__contained_untracked_repo(void)
+{
+ git_status_options opts = GIT_STATUS_OPTIONS_INIT;
+ status_entry_counts counts;
+ git_repository *contained;
+ static const char *expected_files_not_ignored[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "modified",
+ "untracked"
+ };
+ static unsigned int expected_status_not_ignored[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW,
+ };
+ static const char *expected_files_with_untracked[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "dir/file.md",
+ "modified",
+ "untracked"
+ };
+ static const char *expected_files_with_untracked_dir[] = {
+ ".gitmodules",
+ "added",
+ "deleted",
+ "dir/",
+ "modified",
+ "untracked"
+ };
+ static unsigned int expected_status_with_untracked[] = {
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_INDEX_NEW,
+ GIT_STATUS_INDEX_DELETED,
+ GIT_STATUS_WT_NEW,
+ GIT_STATUS_WT_MODIFIED,
+ GIT_STATUS_WT_NEW
+ };
+
+ g_repo = setup_fixture_submodules();
+
+ /* skip empty directory */
+
+ cl_must_pass(p_mkdir("submodules/dir", 0777));
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* still skipping because empty == ignored */
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* find non-ignored contents of directory */
+
+ cl_git_mkfile("submodules/dir/file.md", "hello");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_with_untracked, expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* but skip if all content is ignored */
+
+ cl_git_append2file("submodules/.git/info/exclude", "\n*.md\n\n");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* same is true if it contains a git link */
+
+ cl_git_mkfile("submodules/dir/.git", "gitlink: ../.git");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+
+ /* but if it contains tracked files, it should just show up as a
+ * directory and exclude the files in it
+ */
+
+ cl_git_mkfile("submodules/dir/another_file", "hello");
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_with_untracked_dir,
+ expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* that applies to a git repo with a .git directory too */
+
+ cl_must_pass(p_unlink("submodules/dir/.git"));
+ cl_git_pass(git_repository_init(&contained, "submodules/dir", false));
+ git_repository_free(contained);
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+
+ status_counts_init(
+ counts, expected_files_with_untracked_dir,
+ expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* same result even if we don't recurse into subdirectories */
+
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED;
+
+ status_counts_init(
+ counts, expected_files_with_untracked_dir,
+ expected_status_with_untracked);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(6, counts.entry_count);
+
+ /* and if we remove the untracked file, it goes back to ignored */
+
+ cl_must_pass(p_unlink("submodules/dir/another_file"));
+
+ status_counts_init(
+ counts, expected_files_not_ignored, expected_status_not_ignored);
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, cb_status__match, &counts));
+ cl_assert_equal_i(5, counts.entry_count);
+}