Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
350b83b6
Commit
350b83b6
authored
Oct 18, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #998 from nulltoken/topic/explicit-errors
Enhance test coverage
parents
502be5ff
2df37f42
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
10 deletions
+31
-10
src/diff.c
+10
-6
tests-clar/diff/workdir.c
+17
-0
tests-clar/refs/isvalidname.c
+3
-0
tests-clar/status/worktree.c
+1
-4
No files found.
src/diff.c
View file @
350b83b6
...
@@ -933,12 +933,14 @@ int git_diff_workdir_to_index(
...
@@ -933,12 +933,14 @@ int git_diff_workdir_to_index(
git_diff_list
**
diff
)
git_diff_list
**
diff
)
{
{
git_iterator
*
a
=
NULL
,
*
b
=
NULL
;
git_iterator
*
a
=
NULL
,
*
b
=
NULL
;
int
error
;
char
*
prefix
=
opts
?
diff_prefix_from_pathspec
(
&
opts
->
pathspec
)
:
NULL
;
char
*
prefix
=
opts
?
diff_prefix_from_pathspec
(
&
opts
->
pathspec
)
:
NULL
;
assert
(
repo
&&
diff
);
assert
(
repo
&&
diff
);
if
(
git_iterator_for_index_range
(
&
a
,
repo
,
prefix
,
prefix
)
<
0
||
if
(
(
error
=
git_iterator_for_index_range
(
&
a
,
repo
,
prefix
,
prefix
)
)
<
0
||
git_iterator_for_workdir_range
(
&
b
,
repo
,
prefix
,
prefix
)
<
0
)
(
error
=
git_iterator_for_workdir_range
(
&
b
,
repo
,
prefix
,
prefix
)
)
<
0
)
goto
on_error
;
goto
on_error
;
git__free
(
prefix
);
git__free
(
prefix
);
...
@@ -948,7 +950,7 @@ int git_diff_workdir_to_index(
...
@@ -948,7 +950,7 @@ int git_diff_workdir_to_index(
on_error:
on_error:
git__free
(
prefix
);
git__free
(
prefix
);
git_iterator_free
(
a
);
git_iterator_free
(
a
);
return
-
1
;
return
error
;
}
}
...
@@ -959,12 +961,14 @@ int git_diff_workdir_to_tree(
...
@@ -959,12 +961,14 @@ int git_diff_workdir_to_tree(
git_diff_list
**
diff
)
git_diff_list
**
diff
)
{
{
git_iterator
*
a
=
NULL
,
*
b
=
NULL
;
git_iterator
*
a
=
NULL
,
*
b
=
NULL
;
int
error
;
char
*
prefix
=
opts
?
diff_prefix_from_pathspec
(
&
opts
->
pathspec
)
:
NULL
;
char
*
prefix
=
opts
?
diff_prefix_from_pathspec
(
&
opts
->
pathspec
)
:
NULL
;
assert
(
repo
&&
old_tree
&&
diff
);
assert
(
repo
&&
old_tree
&&
diff
);
if
(
git_iterator_for_tree_range
(
&
a
,
repo
,
old_tree
,
prefix
,
prefix
)
<
0
||
if
(
(
error
=
git_iterator_for_tree_range
(
&
a
,
repo
,
old_tree
,
prefix
,
prefix
)
)
<
0
||
git_iterator_for_workdir_range
(
&
b
,
repo
,
prefix
,
prefix
)
<
0
)
(
error
=
git_iterator_for_workdir_range
(
&
b
,
repo
,
prefix
,
prefix
)
)
<
0
)
goto
on_error
;
goto
on_error
;
git__free
(
prefix
);
git__free
(
prefix
);
...
@@ -974,7 +978,7 @@ int git_diff_workdir_to_tree(
...
@@ -974,7 +978,7 @@ int git_diff_workdir_to_tree(
on_error:
on_error:
git__free
(
prefix
);
git__free
(
prefix
);
git_iterator_free
(
a
);
git_iterator_free
(
a
);
return
-
1
;
return
error
;
}
}
...
...
tests-clar/diff/workdir.c
View file @
350b83b6
#include "clar_libgit2.h"
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "diff_helpers.h"
#include "repository.h"
static
git_repository
*
g_repo
=
NULL
;
static
git_repository
*
g_repo
=
NULL
;
...
@@ -818,3 +819,19 @@ void test_diff_workdir__submodules(void)
...
@@ -818,3 +819,19 @@ void test_diff_workdir__submodules(void)
git_diff_list_free
(
diff
);
git_diff_list_free
(
diff
);
git_tree_free
(
a
);
git_tree_free
(
a
);
}
}
void
test_diff_workdir__cannot_diff_against_a_bare_repository
(
void
)
{
git_diff_options
opts
=
{
0
};
git_diff_list
*
diff
=
NULL
;
git_tree
*
tree
;
g_repo
=
cl_git_sandbox_init
(
"testrepo.git"
);
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_diff_workdir_to_index
(
g_repo
,
&
opts
,
&
diff
));
cl_git_pass
(
git_repository_head_tree
(
&
tree
,
g_repo
));
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_diff_workdir_to_tree
(
g_repo
,
&
opts
,
tree
,
&
diff
));
git_tree_free
(
tree
);
}
tests-clar/refs/isvalidname.c
View file @
350b83b6
...
@@ -21,4 +21,7 @@ void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
...
@@ -21,4 +21,7 @@ void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"ONE_LEVEL"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"ONE_LEVEL"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/stash"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/stash"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/remotes/origin/bim_with_3d@11296"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/remotes/origin/bim_with_3d@11296"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/master{yesterday"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/master}yesterday"
));
cl_assert_equal_i
(
true
,
git_reference_is_valid_name
(
"refs/master{yesterday}"
));
}
}
tests-clar/status/worktree.c
View file @
350b83b6
...
@@ -419,10 +419,7 @@ void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
...
@@ -419,10 +419,7 @@ void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_open
(
&
repo
,
cl_fixture
(
"testrepo.git"
)));
error
=
git_status_file
(
&
status
,
repo
,
"dummy"
);
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_status_file
(
&
status
,
repo
,
"dummy"
));
cl_git_fail
(
error
);
cl_assert
(
error
!=
GIT_ENOTFOUND
);
git_repository_free
(
repo
);
git_repository_free
(
repo
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment