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
da7b78fa
Commit
da7b78fa
authored
Oct 04, 2013
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
index: Make _read() cope with index file creation
parent
6445ae99
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
2 deletions
+53
-2
src/index.c
+3
-2
tests-clar/index/tests.c
+50
-0
No files found.
src/index.c
View file @
da7b78fa
...
...
@@ -461,9 +461,10 @@ int git_index_read(git_index *index)
return
create_index_error
(
-
1
,
"Failed to read index: The index is in-memory only"
);
if
(
!
index
->
on_disk
||
git_path_exists
(
index
->
index_file_path
)
==
false
)
{
index
->
on_disk
=
git_path_exists
(
index
->
index_file_path
);
if
(
!
index
->
on_disk
)
{
git_index_clear
(
index
);
index
->
on_disk
=
0
;
return
0
;
}
...
...
tests-clar/index/tests.c
View file @
da7b78fa
...
...
@@ -484,3 +484,53 @@ void test_index_tests__elocked(void)
git_index_free
(
index
);
git_repository_free
(
repo
);
}
void
test_index_tests__reload_from_disk
(
void
)
{
git_repository
*
repo
;
git_index
*
read_index
;
git_index
*
write_index
;
cl_set_cleanup
(
&
cleanup_myrepo
,
NULL
);
cl_git_pass
(
git_futils_mkdir
(
"./myrepo"
,
NULL
,
0777
,
GIT_MKDIR_PATH
));
cl_git_mkfile
(
"./myrepo/a.txt"
,
"a
\n
"
);
cl_git_mkfile
(
"./myrepo/b.txt"
,
"b
\n
"
);
cl_git_pass
(
git_repository_init
(
&
repo
,
"./myrepo"
,
0
));
cl_git_pass
(
git_repository_index
(
&
write_index
,
repo
));
cl_assert_equal_i
(
false
,
write_index
->
on_disk
);
cl_git_pass
(
git_index_open
(
&
read_index
,
write_index
->
index_file_path
));
cl_assert_equal_i
(
false
,
read_index
->
on_disk
);
/* Stage two new files agaisnt the write_index */
cl_git_pass
(
git_index_add_bypath
(
write_index
,
"a.txt"
));
cl_git_pass
(
git_index_add_bypath
(
write_index
,
"b.txt"
));
cl_assert_equal_sz
(
2
,
git_index_entrycount
(
write_index
));
/* Persist the index changes to disk */
cl_git_pass
(
git_index_write
(
write_index
));
cl_assert_equal_i
(
true
,
write_index
->
on_disk
);
/* Sync the changes back into the read_index */
cl_assert_equal_sz
(
0
,
git_index_entrycount
(
read_index
));
cl_git_pass
(
git_index_read
(
read_index
));
cl_assert_equal_i
(
true
,
read_index
->
on_disk
);
cl_assert_equal_sz
(
2
,
git_index_entrycount
(
read_index
));
/* Remove the index file from the filesystem */
cl_git_pass
(
p_unlink
(
write_index
->
index_file_path
));
/* Sync the changes back into the read_index */
cl_git_pass
(
git_index_read
(
read_index
));
cl_assert_equal_i
(
false
,
read_index
->
on_disk
);
cl_assert_equal_sz
(
0
,
git_index_entrycount
(
read_index
));
git_index_free
(
read_index
);
git_index_free
(
write_index
);
git_repository_free
(
repo
);
}
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