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
69c71f29
Commit
69c71f29
authored
Jun 17, 2016
by
Carlos Martín Nieto
Committed by
GitHub
Jun 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3823 from libgit2/ethomson/checkout_no_index
checkout: use empty baseline when no index file exists
parents
3e9830d7
bb0bd71a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletions
+69
-1
src/checkout.c
+6
-1
tests/checkout/tree.c
+63
-0
No files found.
src/checkout.c
View file @
69c71f29
...
...
@@ -2430,8 +2430,13 @@ static int checkout_data_init(
if
(
!
data
->
opts
.
baseline
&&
!
data
->
opts
.
baseline_index
)
{
data
->
opts_free_baseline
=
true
;
error
=
0
;
error
=
checkout_lookup_head_tree
(
&
data
->
opts
.
baseline
,
repo
);
/* if we don't have an index, this is an initial checkout and
* should be against an empty baseline
*/
if
(
data
->
index
->
on_disk
)
error
=
checkout_lookup_head_tree
(
&
data
->
opts
.
baseline
,
repo
);
if
(
error
==
GIT_EUNBORNBRANCH
)
{
error
=
0
;
...
...
tests/checkout/tree.c
View file @
69c71f29
...
...
@@ -1416,3 +1416,66 @@ void test_checkout_tree__safe_proceeds_if_no_index(void)
git_object_free
(
obj
);
}
static
int
checkout_conflict_count_cb
(
git_checkout_notify_t
why
,
const
char
*
path
,
const
git_diff_file
*
b
,
const
git_diff_file
*
t
,
const
git_diff_file
*
w
,
void
*
payload
)
{
size_t
*
n
=
payload
;
GIT_UNUSED
(
why
);
GIT_UNUSED
(
path
);
GIT_UNUSED
(
b
);
GIT_UNUSED
(
t
);
GIT_UNUSED
(
w
);
(
*
n
)
++
;
return
0
;
}
/* A repo that has a HEAD (even a properly born HEAD that peels to
* a commit) but no index should be treated as if it's an empty baseline
*/
void
test_checkout_tree__baseline_is_empty_when_no_index
(
void
)
{
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_reference
*
head
;
git_object
*
obj
;
git_status_list
*
status
;
size_t
conflicts
=
0
;
assert_on_branch
(
g_repo
,
"master"
);
cl_git_pass
(
git_repository_head
(
&
head
,
g_repo
));
cl_git_pass
(
git_reference_peel
(
&
obj
,
head
,
GIT_OBJ_COMMIT
));
cl_git_pass
(
git_reset
(
g_repo
,
obj
,
GIT_RESET_HARD
,
NULL
));
cl_must_pass
(
p_unlink
(
"testrepo/.git/index"
));
/* for a safe checkout, we should have checkout conflicts with
* the existing untracked files.
*/
opts
.
checkout_strategy
&=
~
GIT_CHECKOUT_FORCE
;
opts
.
notify_flags
=
GIT_CHECKOUT_NOTIFY_CONFLICT
;
opts
.
notify_cb
=
checkout_conflict_count_cb
;
opts
.
notify_payload
=
&
conflicts
;
cl_git_fail_with
(
GIT_ECONFLICT
,
git_checkout_tree
(
g_repo
,
obj
,
&
opts
));
cl_assert_equal_i
(
4
,
conflicts
);
/* but force should succeed and update the index */
opts
.
checkout_strategy
|=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_checkout_tree
(
g_repo
,
obj
,
&
opts
));
cl_git_pass
(
git_status_list_new
(
&
status
,
g_repo
,
NULL
));
cl_assert_equal_i
(
0
,
git_status_list_entrycount
(
status
));
git_status_list_free
(
status
);
git_object_free
(
obj
);
git_reference_free
(
head
);
}
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