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
4ccacdc8
Commit
4ccacdc8
authored
Jul 21, 2017
by
David Catmull
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
status: Add a baseline field to git_status_options for comparing to trees other than HEAD
parent
661cf4d4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
0 deletions
+40
-0
include/git2/status.h
+4
-0
src/status.c
+5
-0
tests/status/worktree.c
+31
-0
No files found.
include/git2/status.h
View file @
4ccacdc8
...
...
@@ -173,12 +173,16 @@ typedef enum {
* The `pathspec` is an array of path patterns to match (using
* fnmatch-style matching), or just an array of paths to match exactly if
* `GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH` is specified in the flags.
*
* The `baseline` is the tree to be used for comparison to the working directory
* and index; defaults to HEAD.
*/
typedef
struct
{
unsigned
int
version
;
git_status_show_t
show
;
unsigned
int
flags
;
git_strarray
pathspec
;
git_tree
*
baseline
;
}
git_status_options
;
#define GIT_STATUS_OPTIONS_VERSION 1
...
...
src/status.c
View file @
4ccacdc8
...
...
@@ -281,12 +281,16 @@ int git_status_list_new(
(
error
=
git_repository_index
(
&
index
,
repo
))
<
0
)
return
error
;
if
(
opts
!=
NULL
&&
opts
->
baseline
!=
NULL
)
{
head
=
opts
->
baseline
;
}
else
{
/* if there is no HEAD, that's okay - we'll make an empty iterator */
if
((
error
=
git_repository_head_tree
(
&
head
,
repo
))
<
0
)
{
if
(
error
!=
GIT_ENOTFOUND
&&
error
!=
GIT_EUNBORNBRANCH
)
goto
done
;
giterr_clear
();
}
}
/* refresh index from disk unless prevented */
if
((
flags
&
GIT_STATUS_OPT_NO_REFRESH
)
==
0
&&
...
...
@@ -377,6 +381,7 @@ done:
*
out
=
status
;
if
(
opts
==
NULL
||
opts
->
baseline
!=
head
)
git_tree_free
(
head
);
git_index_free
(
index
);
...
...
tests/status/worktree.c
View file @
4ccacdc8
...
...
@@ -1280,3 +1280,34 @@ void test_status_worktree__with_directory_in_pathlist(void)
git_status_list_free
(
statuslist
);
}
void
test_status_worktree__at_head_parent
(
void
)
{
git_repository
*
repo
=
cl_git_sandbox_init
(
"empty_standard_repo"
);
git_status_options
opts
=
GIT_STATUS_OPTIONS_INIT
;
git_status_list
*
statuslist
;
git_tree
*
parent_tree
;
const
git_status_entry
*
status
;
cl_git_mkfile
(
"empty_standard_repo/file1"
,
"ping"
);
stage_and_commit
(
repo
,
"file1"
);
cl_git_pass
(
git_repository_head_tree
(
&
parent_tree
,
repo
));
cl_git_mkfile
(
"empty_standard_repo/file2"
,
"pong"
);
stage_and_commit
(
repo
,
"file2"
);
cl_git_rewritefile
(
"empty_standard_repo/file2"
,
"pyng"
);
opts
.
show
=
GIT_STATUS_SHOW_INDEX_AND_WORKDIR
;
opts
.
baseline
=
parent_tree
;
cl_git_pass
(
git_status_list_new
(
&
statuslist
,
repo
,
&
opts
));
cl_assert_equal_sz
(
1
,
git_status_list_entrycount
(
statuslist
));
status
=
git_status_byindex
(
statuslist
,
0
);
cl_assert
(
status
!=
NULL
);
cl_assert_equal_s
(
"file2"
,
status
->
index_to_workdir
->
old_file
.
path
);
cl_assert_equal_i
(
GIT_STATUS_WT_MODIFIED
|
GIT_STATUS_INDEX_NEW
,
status
->
status
);
git_tree_free
(
parent_tree
);
git_status_list_free
(
statuslist
);
}
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