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
1aa1b09e
Commit
1aa1b09e
authored
Jun 15, 2011
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #260 from nulltoken/fix/git_index_add
Fix git_index_add()
parents
61438604
8e11e707
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
4 deletions
+45
-4
src/blob.c
+2
-2
src/fileops.c
+1
-1
tests/t06-index.c
+42
-1
No files found.
src/blob.c
View file @
1aa1b09e
...
...
@@ -119,9 +119,9 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
ssize_t
read_len
;
if
(
!
islnk
)
read_len
=
gitfo_read
(
fd
,
buffer
,
sizeof
(
buffer
));
read_len
=
gitfo_read
(
fd
,
buffer
,
(
size_t
)(
size
<
sizeof
(
buffer
)
?
size
:
sizeof
(
buffer
)
));
else
read_len
=
gitfo_readlink
(
full_path
,
buffer
,
sizeof
(
buffer
)
);
read_len
=
gitfo_readlink
(
full_path
,
buffer
,
(
size_t
)
size
);
if
(
read_len
<
0
)
{
if
(
!
islnk
)
...
...
src/fileops.c
View file @
1aa1b09e
...
...
@@ -97,7 +97,7 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
cnt
-=
r
;
b
+=
r
;
}
return
GIT_SUCCESS
;
return
(
int
)(
b
-
(
char
*
)
buf
)
;
}
int
gitfo_write
(
git_file
fd
,
void
*
buf
,
size_t
cnt
)
...
...
tests/t06-index.c
View file @
1aa1b09e
...
...
@@ -161,7 +161,6 @@ BEGIN_TEST(sort0, "sort the entires in an index")
*/
END_TEST
BEGIN_TEST
(
sort1
,
"sort the entires in an empty index"
)
git_index
*
index
;
...
...
@@ -173,6 +172,46 @@ BEGIN_TEST(sort1, "sort the entires in an empty index")
git_index_free
(
index
);
END_TEST
BEGIN_TEST
(
add0
,
"add a new file to the index"
)
git_index
*
index
;
git_filebuf
file
;
git_repository
*
repo
;
git_index_entry
*
entry
;
git_oid
id1
;
/* Intialize a new repository */
must_pass
(
git_repository_init
(
&
repo
,
TEMP_REPO_FOLDER
"myrepo"
,
0
));
/* Ensure we're the only guy in the room */
must_pass
(
git_repository_index
(
&
index
,
repo
));
must_pass
(
git_index_entrycount
(
index
)
==
0
);
/* Create a new file in the working directory */
must_pass
(
gitfo_mkdir_2file
(
TEMP_REPO_FOLDER
"myrepo/test.txt"
));
must_pass
(
git_filebuf_open
(
&
file
,
TEMP_REPO_FOLDER
"myrepo/test.txt"
,
0
));
must_pass
(
git_filebuf_write
(
&
file
,
"hey there
\n
"
,
10
));
must_pass
(
git_filebuf_commit
(
&
file
));
/* Store the expected hash of the file/blob
* This has been generated by executing the following
* $ echo "hey there" | git hash-object --stdin
*/
must_pass
(
git_oid_mkstr
(
&
id1
,
"a8233120f6ad708f843d861ce2b7228ec4e3dec6"
));
/* Add the new file to the index */
must_pass
(
git_index_add
(
index
,
"test.txt"
,
0
));
/* Wow... it worked! */
must_pass
(
git_index_entrycount
(
index
)
==
1
);
entry
=
git_index_get
(
index
,
0
);
/* And the built-in hashing mechanism worked as expected */
must_be_true
(
git_oid_cmp
(
&
id1
,
&
entry
->
oid
)
==
0
);
git_repository_free
(
repo
);
rmdir_recurs
(
TEMP_REPO_FOLDER
);
END_TEST
BEGIN_SUITE
(
index
)
ADD_TEST
(
read0
);
ADD_TEST
(
read1
);
...
...
@@ -185,4 +224,6 @@ BEGIN_SUITE(index)
ADD_TEST
(
sort0
);
ADD_TEST
(
sort1
);
ADD_TEST
(
add0
);
END_SUITE
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