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
d0dd3fce
Commit
d0dd3fce
authored
Feb 18, 2015
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stash apply: check out a tree, not piecewise
parent
7f26b1b9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
33 deletions
+12
-33
src/stash.c
+10
-31
tests/stash/apply.c
+2
-2
No files found.
src/stash.c
View file @
d0dd3fce
...
@@ -652,7 +652,7 @@ static int apply_index(
...
@@ -652,7 +652,7 @@ static int apply_index(
git_tree
*
index_parent_tree
,
git_tree
*
index_parent_tree
,
git_tree
*
index_tree
)
git_tree
*
index_tree
)
{
{
git_index
*
unstashed_index
=
NULL
;
git_index
*
unstashed_index
=
NULL
;
git_merge_options
options
=
GIT_MERGE_OPTIONS_INIT
;
git_merge_options
options
=
GIT_MERGE_OPTIONS_INIT
;
int
error
;
int
error
;
git_oid
oid
;
git_oid
oid
;
...
@@ -675,43 +675,22 @@ cleanup:
...
@@ -675,43 +675,22 @@ cleanup:
static
int
apply_untracked
(
static
int
apply_untracked
(
git_repository
*
repo
,
git_repository
*
repo
,
git_tree
*
start_index_tree
,
git_tree
*
untracked_tree
)
git_tree
*
untracked_tree
)
{
{
git_checkout_options
options
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_checkout_options
options
=
GIT_CHECKOUT_OPTIONS_INIT
;
size_t
i
,
count
;
git_index
*
merged_index
=
NULL
;
unsigned
int
status
;
int
error
;
int
error
;
for
(
i
=
0
,
count
=
git_tree_entrycount
(
untracked_tree
);
i
<
count
;
++
i
)
{
options
.
checkout_strategy
=
const
git_tree_entry
*
entry
=
git_tree_entry_byindex
(
untracked_tree
,
i
);
GIT_CHECKOUT_SAFE
|
GIT_CHECKOUT_DONT_UPDATE_INDEX
;
const
char
*
path
=
git_tree_entry_name
(
entry
);
error
=
git_status_file
(
&
status
,
repo
,
path
);
if
(
!
error
)
{
giterr_set
(
GITERR_STASH
,
"Untracked or ignored file '%s' already exists"
,
path
);
return
GIT_EEXISTS
;
}
}
/*
if
((
error
=
git_merge_trees
(
&
merged_index
,
The untracked tree only contains the untracked / ignores files so checking
repo
,
NULL
,
start_index_tree
,
untracked_tree
,
NULL
))
==
0
)
it out would remove all other files in the workdir. Since git_checkout_tree()
error
=
git_checkout_index
(
repo
,
merged_index
,
&
options
);
does not have a mode to leave removed files alone, we emulate it by checking
out files from the untracked tree one by one.
*/
options
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
|
GIT_CHECKOUT_DONT_UPDATE_INDEX
;
options
.
paths
.
count
=
1
;
for
(
i
=
0
,
count
=
git_tree_entrycount
(
untracked_tree
);
i
<
count
;
++
i
)
{
const
git_tree_entry
*
entry
=
git_tree_entry_byindex
(
untracked_tree
,
i
);
const
char
*
name
=
git_tree_entry_name
(
entry
);
git_index_free
(
merged_index
);
options
.
paths
.
strings
=
(
char
**
)
&
name
;
if
((
error
=
git_checkout_tree
(
repo
,
(
git_object
*
)
untracked_tree
,
&
options
))
<
0
)
return
error
;
return
error
;
}
return
0
;
}
}
static
int
checkout_modified_notify_callback
(
static
int
checkout_modified_notify_callback
(
...
@@ -871,7 +850,7 @@ int git_stash_apply(
...
@@ -871,7 +850,7 @@ int git_stash_apply(
/* If applicable, restore untracked / ignored files in workdir */
/* If applicable, restore untracked / ignored files in workdir */
if
(
untracked_tree
)
{
if
(
untracked_tree
)
{
if
((
error
=
apply_untracked
(
repo
,
untracked_tree
))
<
0
)
if
((
error
=
apply_untracked
(
repo
,
start_index_tree
,
untracked_tree
))
<
0
)
goto
cleanup
;
goto
cleanup
;
}
}
...
...
tests/stash/apply.c
View file @
d0dd3fce
...
@@ -121,7 +121,7 @@ void test_stash_apply__conflict_untracked_with_default(void)
...
@@ -121,7 +121,7 @@ void test_stash_apply__conflict_untracked_with_default(void)
{
{
cl_git_mkfile
(
"stash/when"
,
"nothing
\n
"
);
cl_git_mkfile
(
"stash/when"
,
"nothing
\n
"
);
cl_git_fail_with
(
git_stash_apply
(
repo
,
0
,
GIT_APPLY_DEFAULT
),
GIT_E
EXISTS
);
cl_git_fail_with
(
git_stash_apply
(
repo
,
0
,
GIT_APPLY_DEFAULT
),
GIT_E
MERGECONFLICT
);
cl_assert_equal_i
(
git_index_has_conflicts
(
repo_index
),
0
);
cl_assert_equal_i
(
git_index_has_conflicts
(
repo_index
),
0
);
assert_status
(
repo
,
"what"
,
GIT_STATUS_CURRENT
);
assert_status
(
repo
,
"what"
,
GIT_STATUS_CURRENT
);
...
@@ -134,7 +134,7 @@ void test_stash_apply__conflict_untracked_with_reinstate_index(void)
...
@@ -134,7 +134,7 @@ void test_stash_apply__conflict_untracked_with_reinstate_index(void)
{
{
cl_git_mkfile
(
"stash/when"
,
"nothing
\n
"
);
cl_git_mkfile
(
"stash/when"
,
"nothing
\n
"
);
cl_git_fail_with
(
git_stash_apply
(
repo
,
0
,
GIT_APPLY_REINSTATE_INDEX
),
GIT_E
EXISTS
);
cl_git_fail_with
(
git_stash_apply
(
repo
,
0
,
GIT_APPLY_REINSTATE_INDEX
),
GIT_E
MERGECONFLICT
);
cl_assert_equal_i
(
git_index_has_conflicts
(
repo_index
),
0
);
cl_assert_equal_i
(
git_index_has_conflicts
(
repo_index
),
0
);
assert_status
(
repo
,
"what"
,
GIT_STATUS_CURRENT
);
assert_status
(
repo
,
"what"
,
GIT_STATUS_CURRENT
);
...
...
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