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
bcc62293
Commit
bcc62293
authored
Apr 09, 2014
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2259 from libgit2/vmg/state-cleanup
Rewrite `state-cleanup`
parents
361e9192
c3dcbe84
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
12 deletions
+41
-12
src/repository.c
+23
-12
tests/repo/state.c
+18
-0
No files found.
src/repository.c
View file @
bcc62293
...
...
@@ -1955,24 +1955,32 @@ int git_repository_state(git_repository *repo)
return
state
;
}
int
git_repository__cleanup_files
(
git_repository
*
repo
,
const
char
*
files
[],
size_t
files_len
)
int
git_repository__cleanup_files
(
git_repository
*
repo
,
const
char
*
files
[],
size_t
files_len
)
{
git_buf
path
=
GIT_BUF_INIT
;
git_buf
buf
=
GIT_BUF_INIT
;
size_t
i
;
int
error
=
0
;
int
error
;
for
(
i
=
0
;
i
<
files_len
;
++
i
)
{
git_buf_clear
(
&
path
)
;
for
(
error
=
0
,
i
=
0
;
!
error
&&
i
<
files_len
;
++
i
)
{
const
char
*
path
;
if
((
error
=
git_buf_joinpath
(
&
path
,
repo
->
path_repository
,
files
[
i
]))
<
0
||
(
git_path_isfile
(
git_buf_cstr
(
&
path
))
&&
(
error
=
p_unlink
(
git_buf_cstr
(
&
path
)))
<
0
))
goto
done
;
}
if
(
git_buf_joinpath
(
&
buf
,
repo
->
path_repository
,
files
[
i
])
<
0
)
return
-
1
;
done:
git_buf_free
(
&
path
);
path
=
git_buf_cstr
(
&
buf
);
if
(
git_path_isfile
(
path
))
{
error
=
p_unlink
(
path
);
}
else
if
(
git_path_isdir
(
path
))
{
error
=
git_futils_rmdir_r
(
path
,
NULL
,
GIT_RMDIR_REMOVE_FILES
|
GIT_RMDIR_REMOVE_BLOCKERS
);
}
git_buf_clear
(
&
buf
);
}
git_buf_free
(
&
buf
);
return
error
;
}
...
...
@@ -1982,6 +1990,9 @@ static const char *state_files[] = {
GIT_MERGE_MSG_FILE
,
GIT_REVERT_HEAD_FILE
,
GIT_CHERRY_PICK_HEAD_FILE
,
GIT_BISECT_LOG_FILE
,
GIT_REBASE_MERGE_DIR
,
GIT_REBASE_APPLY_DIR
,
};
int
git_repository_state_cleanup
(
git_repository
*
repo
)
...
...
tests/repo/state.c
View file @
bcc62293
...
...
@@ -45,52 +45,70 @@ void test_repo_state__merge(void)
{
setup_simple_state
(
GIT_MERGE_HEAD_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_MERGE
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__revert
(
void
)
{
setup_simple_state
(
GIT_REVERT_HEAD_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_REVERT
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__cherry_pick
(
void
)
{
setup_simple_state
(
GIT_CHERRY_PICK_HEAD_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_CHERRY_PICK
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__bisect
(
void
)
{
setup_simple_state
(
GIT_BISECT_LOG_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_BISECT
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__rebase_interactive
(
void
)
{
setup_simple_state
(
GIT_REBASE_MERGE_INTERACTIVE_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_REBASE_INTERACTIVE
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__rebase_merge
(
void
)
{
setup_simple_state
(
GIT_REBASE_MERGE_DIR
"whatever"
);
assert_repo_state
(
GIT_REPOSITORY_STATE_REBASE_MERGE
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__rebase
(
void
)
{
setup_simple_state
(
GIT_REBASE_APPLY_REBASING_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_REBASE
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__apply_mailbox
(
void
)
{
setup_simple_state
(
GIT_REBASE_APPLY_APPLYING_FILE
);
assert_repo_state
(
GIT_REPOSITORY_STATE_APPLY_MAILBOX
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
void
test_repo_state__apply_mailbox_or_rebase
(
void
)
{
setup_simple_state
(
GIT_REBASE_APPLY_DIR
"whatever"
);
assert_repo_state
(
GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE
);
cl_git_pass
(
git_repository_state_cleanup
(
_repo
));
assert_repo_state
(
GIT_REPOSITORY_STATE_NONE
);
}
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