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
d2c4f764
Commit
d2c4f764
authored
Jun 11, 2017
by
Edward Thomson
Committed by
GitHub
Jun 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4260 from libgit2/ethomson/forced_checkout_2
Update to forced checkout and untracked files
parents
e476d528
4a0df574
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
5 deletions
+82
-5
src/checkout.c
+2
-4
src/fileops.c
+3
-0
tests/checkout/head.c
+77
-1
No files found.
src/checkout.c
View file @
d2c4f764
...
...
@@ -370,10 +370,8 @@ static int checkout_action_wd_only(
*/
const
git_index_entry
*
e
=
git_index_get_byindex
(
data
->
index
,
pos
);
if
(
e
!=
NULL
&&
data
->
diff
->
pfxcomp
(
e
->
path
,
wd
->
path
)
==
0
)
{
notify
=
GIT_CHECKOUT_NOTIFY_DIRTY
;
remove
=
((
data
->
strategy
&
GIT_CHECKOUT_FORCE
)
!=
0
);
}
if
(
e
!=
NULL
&&
data
->
diff
->
pfxcomp
(
e
->
path
,
wd
->
path
)
==
0
)
return
git_iterator_advance_into
(
wditem
,
workdir
);
}
}
...
...
src/fileops.c
View file @
d2c4f764
...
...
@@ -770,6 +770,9 @@ static int futils__rmdir_empty_parent(void *opaque, const char *path)
if
(
en
==
ENOENT
||
en
==
ENOTDIR
)
{
/* do nothing */
}
else
if
((
data
->
flags
&
GIT_RMDIR_SKIP_NONEMPTY
)
==
0
&&
en
==
EBUSY
)
{
error
=
git_path_set_error
(
errno
,
path
,
"rmdir"
);
}
else
if
(
en
==
ENOTEMPTY
||
en
==
EEXIST
||
en
==
EBUSY
)
{
error
=
GIT_ITEROVER
;
}
else
{
...
...
tests/checkout/head.c
View file @
d2c4f764
...
...
@@ -38,7 +38,7 @@ void test_checkout_head__with_index_only_tree(void)
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
p_mkdir
(
"testrepo/newdir"
,
0777
);
cl_git_mkfile
(
"testrepo/newdir/newfile.txt"
,
"new file
\n
"
);
cl_git_mkfile
(
"testrepo/newdir/newfile.txt"
,
"new file
\n
"
);
cl_git_pass
(
git_index_add_bypath
(
index
,
"newdir/newfile.txt"
));
cl_git_pass
(
git_index_write
(
index
));
...
...
@@ -60,3 +60,79 @@ void test_checkout_head__with_index_only_tree(void)
git_index_free
(
index
);
}
void
test_checkout_head__do_not_remove_untracked_file
(
void
)
{
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_index
*
index
;
cl_git_pass
(
p_mkdir
(
"testrepo/tracked"
,
0755
));
cl_git_mkfile
(
"testrepo/tracked/tracked"
,
"tracked
\n
"
);
cl_git_mkfile
(
"testrepo/tracked/untracked"
,
"untracked
\n
"
);
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"tracked/tracked"
));
cl_git_pass
(
git_index_write
(
index
));
git_index_free
(
index
);
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_checkout_head
(
g_repo
,
&
opts
));
cl_assert
(
!
git_path_isfile
(
"testrepo/tracked/tracked"
));
cl_assert
(
git_path_isfile
(
"testrepo/tracked/untracked"
));
}
void
test_checkout_head__do_not_remove_untracked_file_in_subdir
(
void
)
{
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_index
*
index
;
cl_git_pass
(
p_mkdir
(
"testrepo/tracked"
,
0755
));
cl_git_pass
(
p_mkdir
(
"testrepo/tracked/subdir"
,
0755
));
cl_git_mkfile
(
"testrepo/tracked/tracked"
,
"tracked
\n
"
);
cl_git_mkfile
(
"testrepo/tracked/subdir/tracked"
,
"tracked
\n
"
);
cl_git_mkfile
(
"testrepo/tracked/subdir/untracked"
,
"untracked
\n
"
);
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"tracked/tracked"
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"tracked/subdir/tracked"
));
cl_git_pass
(
git_index_write
(
index
));
git_index_free
(
index
);
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_checkout_head
(
g_repo
,
&
opts
));
cl_assert
(
!
git_path_isfile
(
"testrepo/tracked/tracked"
));
cl_assert
(
!
git_path_isfile
(
"testrepo/tracked/subdir/tracked"
));
cl_assert
(
git_path_isfile
(
"testrepo/tracked/subdir/untracked"
));
}
void
test_checkout_head__do_remove_tracked_subdir
(
void
)
{
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_index
*
index
;
cl_git_pass
(
p_mkdir
(
"testrepo/subdir"
,
0755
));
cl_git_pass
(
p_mkdir
(
"testrepo/subdir/tracked"
,
0755
));
cl_git_mkfile
(
"testrepo/subdir/tracked-file"
,
"tracked
\n
"
);
cl_git_mkfile
(
"testrepo/subdir/untracked-file"
,
"untracked
\n
"
);
cl_git_mkfile
(
"testrepo/subdir/tracked/tracked1"
,
"tracked
\n
"
);
cl_git_mkfile
(
"testrepo/subdir/tracked/tracked2"
,
"tracked
\n
"
);
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"subdir/tracked-file"
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"subdir/tracked/tracked1"
));
cl_git_pass
(
git_index_add_bypath
(
index
,
"subdir/tracked/tracked2"
));
cl_git_pass
(
git_index_write
(
index
));
git_index_free
(
index
);
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_checkout_head
(
g_repo
,
&
opts
));
cl_assert
(
!
git_path_isdir
(
"testrepo/subdir/tracked"
));
cl_assert
(
!
git_path_isfile
(
"testrepo/subdir/tracked-file"
));
cl_assert
(
git_path_isfile
(
"testrepo/subdir/untracked-file"
));
}
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