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
25743bd7
Commit
25743bd7
authored
Jan 12, 2013
by
Edward Thomson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add an index_remove_bypath that removes conflicts, renamed add_from_workdir to match
parent
e2d2c6e5
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
94 additions
and
44 deletions
+94
-44
include/git2/index.h
+18
-2
src/index.c
+16
-1
src/stash.c
+1
-1
src/submodule.c
+1
-1
tests-clar/attr/repo.c
+1
-1
tests-clar/checkout/head.c
+1
-1
tests-clar/checkout/index.c
+2
-2
tests-clar/checkout/tree.c
+1
-1
tests-clar/index/conflicts.c
+21
-2
tests-clar/index/filemodes.c
+1
-1
tests-clar/index/inmemory.c
+2
-2
tests-clar/index/read_tree.c
+3
-3
tests-clar/index/rename.c
+2
-2
tests-clar/index/stage.c
+1
-1
tests-clar/index/tests.c
+9
-9
tests-clar/object/commit/commitstagedfile.c
+1
-1
tests-clar/stash/drop.c
+1
-1
tests-clar/stash/save.c
+2
-2
tests-clar/stash/stash_helpers.c
+6
-6
tests-clar/status/worktree_init.c
+4
-4
No files found.
include/git2/index.h
View file @
25743bd7
...
...
@@ -362,7 +362,7 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
/**@{*/
/**
* Add or update an index entry from a file
i
n disk
* Add or update an index entry from a file
o
n disk
*
* The file `path` must be relative to the repository's
* working folder and must be readable.
...
...
@@ -381,7 +381,23 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
* @param path filename to add
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_index_add_from_workdir
(
git_index
*
index
,
const
char
*
path
);
GIT_EXTERN
(
int
)
git_index_add_bypath
(
git_index
*
index
,
const
char
*
path
);
/**
* Remove an index entry corresponding to a file on disk
*
* The file `path` must be relative to the repository's
* working folder. It may exist.
*
* If this file currently is the result of a merge conflict, this
* file will no longer be marked as conflicting. The data about
* the conflict will be moved to the "resolve undo" (REUC) section.
*
* @param index an existing index object
* @param path filename to remove
* @return 0 or an error code
*/
GIT_EXTERN
(
int
)
git_index_remove_bypath
(
git_index
*
index
,
const
char
*
path
);
/**
* Find the first index of any entries which point to given
...
...
src/index.c
View file @
25743bd7
...
...
@@ -730,7 +730,7 @@ static int index_conflict_to_reuc(git_index *index, const char *path)
return
ret
;
}
int
git_index_add_
from_workdir
(
git_index
*
index
,
const
char
*
path
)
int
git_index_add_
bypath
(
git_index
*
index
,
const
char
*
path
)
{
git_index_entry
*
entry
=
NULL
;
int
ret
;
...
...
@@ -753,6 +753,21 @@ on_error:
return
ret
;
}
int
git_index_remove_bypath
(
git_index
*
index
,
const
char
*
path
)
{
int
ret
;
assert
(
index
&&
path
);
if
(((
ret
=
git_index_remove
(
index
,
path
,
0
))
<
0
&&
ret
!=
GIT_ENOTFOUND
)
||
((
ret
=
index_conflict_to_reuc
(
index
,
path
))
<
0
&&
ret
!=
GIT_ENOTFOUND
))
return
ret
;
return
0
;
}
int
git_index_add
(
git_index
*
index
,
const
git_index_entry
*
source_entry
)
{
git_index_entry
*
entry
=
NULL
;
...
...
src/stash.c
View file @
25743bd7
...
...
@@ -208,7 +208,7 @@ static int update_index_cb(
}
if
(
add_path
!=
NULL
)
data
->
error
=
git_index_add_
from_workdir
(
data
->
index
,
add_path
);
data
->
error
=
git_index_add_
bypath
(
data
->
index
,
add_path
);
return
data
->
error
;
}
...
...
src/submodule.c
View file @
25743bd7
...
...
@@ -332,7 +332,7 @@ int git_submodule_add_finalize(git_submodule *sm)
assert
(
sm
);
if
((
error
=
git_repository_index__weakptr
(
&
index
,
sm
->
owner
))
<
0
||
(
error
=
git_index_add_
from_workdir
(
index
,
GIT_MODULES_FILE
))
<
0
)
(
error
=
git_index_add_
bypath
(
index
,
GIT_MODULES_FILE
))
<
0
)
return
error
;
return
git_submodule_add_to_index
(
sm
,
true
);
...
...
tests-clar/attr/repo.c
View file @
25743bd7
...
...
@@ -270,7 +270,7 @@ static void assert_proper_normalization(git_index *index, const char *filename,
const
git_index_entry
*
entry
;
add_to_workdir
(
filename
,
CONTENT
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
filename
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
filename
));
index_pos
=
git_index_find
(
index
,
filename
);
cl_assert
(
index_pos
>=
0
);
...
...
tests-clar/checkout/head.c
View file @
25743bd7
...
...
@@ -40,7 +40,7 @@ void test_checkout_head__with_index_only_tree(void)
p_mkdir
(
"testrepo/newdir"
,
0777
);
cl_git_mkfile
(
"testrepo/newdir/newfile.txt"
,
"new file
\n
"
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"newdir/newfile.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"newdir/newfile.txt"
));
cl_git_pass
(
git_index_write
(
index
));
cl_assert
(
git_path_isfile
(
"testrepo/newdir/newfile.txt"
));
...
...
tests-clar/checkout/index.c
View file @
25743bd7
...
...
@@ -417,8 +417,8 @@ void test_checkout_index__can_overcome_name_clashes(void)
cl_git_pass
(
p_mkdir
(
"./testrepo/path1"
,
0777
));
cl_git_mkfile
(
"./testrepo/path1/file1"
,
"content
\r\n
"
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"path0"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"path1/file1"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"path0"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"path1/file1"
));
cl_git_pass
(
p_unlink
(
"./testrepo/path0"
));
cl_git_pass
(
git_futils_rmdir_r
(
...
...
tests-clar/checkout/tree.c
View file @
25743bd7
...
...
@@ -406,7 +406,7 @@ void assert_conflict(
GIT_EMERGECONFLICT
,
git_checkout_tree
(
g_repo
,
g_object
,
&
g_opts
));
/* Stage the conflicting change */
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
entry_path
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
entry_path
));
cl_git_pass
(
git_index_write
(
index
));
cl_assert_equal_i
(
...
...
tests-clar/index/conflicts.c
View file @
25743bd7
...
...
@@ -154,7 +154,7 @@ void test_index_conflicts__remove(void)
}
}
void
test_index_conflicts__moved_to_reuc
(
void
)
void
test_index_conflicts__moved_to_reuc
_on_add
(
void
)
{
const
git_index_entry
*
entry
;
size_t
i
;
...
...
@@ -163,7 +163,7 @@ void test_index_conflicts__moved_to_reuc(void)
cl_git_mkfile
(
"./mergedrepo/conflicts-one.txt"
,
"new-file
\n
"
);
cl_git_pass
(
git_index_add_
from_workdir
(
repo_index
,
"conflicts-one.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
repo_index
,
"conflicts-one.txt"
));
cl_assert
(
git_index_entrycount
(
repo_index
)
==
6
);
...
...
@@ -175,6 +175,25 @@ void test_index_conflicts__moved_to_reuc(void)
}
}
void
test_index_conflicts__moved_to_reuc_on_remove
(
void
)
{
const
git_index_entry
*
entry
;
size_t
i
;
cl_assert
(
git_index_entrycount
(
repo_index
)
==
8
);
cl_git_pass
(
p_unlink
(
"./mergedrepo/conflicts-one.txt"
));
cl_git_pass
(
git_index_remove_bypath
(
repo_index
,
"conflicts-one.txt"
));
cl_assert
(
git_index_entrycount
(
repo_index
)
==
5
);
for
(
i
=
0
;
i
<
git_index_entrycount
(
repo_index
);
i
++
)
{
cl_assert
(
entry
=
git_index_get_byindex
(
repo_index
,
i
));
cl_assert
(
strcmp
(
entry
->
path
,
"conflicts-one.txt"
)
!=
0
);
}
}
void
test_index_conflicts__remove_all_conflicts
(
void
)
{
size_t
i
;
...
...
tests-clar/index/filemodes.c
View file @
25743bd7
...
...
@@ -56,7 +56,7 @@ static void add_and_check_mode(
int
pos
;
const
git_index_entry
*
entry
;
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
filename
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
filename
));
pos
=
git_index_find
(
index
,
filename
);
cl_assert
(
pos
>=
0
);
...
...
tests-clar/index/inmemory.c
View file @
25743bd7
...
...
@@ -10,13 +10,13 @@ void test_index_inmemory__can_create_an_inmemory_index(void)
git_index_free
(
index
);
}
void
test_index_inmemory__cannot_add_
from_workdir
_to_an_inmemory_index
(
void
)
void
test_index_inmemory__cannot_add_
bypath
_to_an_inmemory_index
(
void
)
{
git_index
*
index
;
cl_git_pass
(
git_index_new
(
&
index
));
cl_assert_equal_i
(
GIT_ERROR
,
git_index_add_
from_workdir
(
index
,
"test.txt"
));
cl_assert_equal_i
(
GIT_ERROR
,
git_index_add_
bypath
(
index
,
"test.txt"
));
git_index_free
(
index
);
}
tests-clar/index/read_tree.c
View file @
25743bd7
...
...
@@ -24,9 +24,9 @@ void test_index_read_tree__read_write_involution(void)
cl_git_mkfile
(
"./read_tree/abc/d"
,
NULL
);
cl_git_mkfile
(
"./read_tree/abc_d"
,
NULL
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"abc-d"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"abc_d"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"abc/d"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"abc-d"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"abc_d"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"abc/d"
));
/* write-tree */
cl_git_pass
(
git_index_write_tree
(
&
expected
,
index
));
...
...
tests-clar/index/rename.c
View file @
25743bd7
...
...
@@ -19,7 +19,7 @@ void test_index_rename__single_file(void)
cl_git_mkfile
(
"./rename/lame.name.txt"
,
"new_file
\n
"
);
/* This should add a new blob to the object database in 'd4/fa8600b4f37d7516bef4816ae2c64dbf029e3a' */
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"lame.name.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"lame.name.txt"
));
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
cl_git_pass
(
git_oid_fromstr
(
&
expected
,
"d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"
));
...
...
@@ -35,7 +35,7 @@ void test_index_rename__single_file(void)
p_rename
(
"./rename/lame.name.txt"
,
"./rename/fancy.name.txt"
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"fancy.name.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"fancy.name.txt"
));
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
position
=
git_index_find
(
index
,
"fancy.name.txt"
);
...
...
tests-clar/index/stage.c
View file @
25743bd7
...
...
@@ -31,7 +31,7 @@ void test_index_stage__add_always_adds_stage_0(void)
cl_git_mkfile
(
"./mergedrepo/new-file.txt"
,
"new-file
\n
"
);
cl_git_pass
(
git_index_add_
from_workdir
(
repo_index
,
"new-file.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
repo_index
,
"new-file.txt"
));
cl_assert
((
entry_idx
=
git_index_find
(
repo_index
,
"new-file.txt"
))
>=
0
);
cl_assert
((
entry
=
git_index_get_byindex
(
repo_index
,
entry_idx
))
!=
NULL
);
...
...
tests-clar/index/tests.c
View file @
25743bd7
...
...
@@ -233,7 +233,7 @@ void test_index_tests__add(void)
cl_git_pass
(
git_oid_fromstr
(
&
id1
,
"a8233120f6ad708f843d861ce2b7228ec4e3dec6"
));
/* Add the new file to the index */
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"test.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"test.txt"
));
/* Wow... it worked! */
cl_assert
(
git_index_entrycount
(
index
)
==
1
);
...
...
@@ -250,7 +250,7 @@ void test_index_tests__add(void)
git_repository_free
(
repo
);
}
void
test_index_tests__add_
from_workdir
_to_a_bare_repository_returns_EBAREPO
(
void
)
void
test_index_tests__add_
bypath
_to_a_bare_repository_returns_EBAREPO
(
void
)
{
git_repository
*
bare_repo
;
git_index
*
index
;
...
...
@@ -258,7 +258,7 @@ void test_index_tests__add_from_workdir_to_a_bare_repository_returns_EBAREPO(voi
cl_git_pass
(
git_repository_open
(
&
bare_repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_repository_index
(
&
index
,
bare_repo
));
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_index_add_
from_workdir
(
index
,
"test.txt"
));
cl_assert_equal_i
(
GIT_EBAREREPO
,
git_index_add_
bypath
(
index
,
"test.txt"
));
git_index_free
(
index
);
git_repository_free
(
bare_repo
);
...
...
@@ -280,7 +280,7 @@ void test_index_tests__write_invalid_filename(void)
cl_git_mkfile
(
"./read_tree/.git/hello"
,
NULL
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
".git/hello"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
".git/hello"
));
/* write-tree */
cl_git_fail
(
git_index_write_tree
(
&
expected
,
index
));
...
...
@@ -303,7 +303,7 @@ void test_index_tests__remove_entry(void)
cl_assert
(
git_index_entrycount
(
index
)
==
0
);
cl_git_mkfile
(
"index_test/hello"
,
NULL
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"hello"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"hello"
));
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_index_read
(
index
));
/* reload */
...
...
@@ -339,10 +339,10 @@ void test_index_tests__remove_directory(void)
cl_git_mkfile
(
"index_test/a/3.txt"
,
NULL
);
cl_git_mkfile
(
"index_test/b.txt"
,
NULL
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"a/1.txt"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"a/2.txt"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"a/3.txt"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"b.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"a/1.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"a/2.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"a/3.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"b.txt"
));
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_index_read
(
index
));
/* reload */
...
...
tests-clar/object/commit/commitstagedfile.c
View file @
25743bd7
...
...
@@ -73,7 +73,7 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
*/
cl_git_mkfile
(
"treebuilder/test.txt"
,
"test
\n
"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"test.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"test.txt"
));
entry
=
git_index_get_byindex
(
index
,
0
);
...
...
tests-clar/stash/drop.c
View file @
25743bd7
...
...
@@ -34,7 +34,7 @@ static void push_three_states(void)
cl_git_mkfile
(
"stash/zero.txt"
,
"content
\n
"
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"zero.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"zero.txt"
));
commit_staged_files
(
&
oid
,
index
,
signature
);
cl_assert
(
git_path_exists
(
"stash/zero.txt"
));
...
...
tests-clar/stash/save.c
View file @
25743bd7
...
...
@@ -251,8 +251,8 @@ void test_stash_save__cannot_stash_when_there_are_no_local_change(void)
* 'what' and 'who' are being committed.
* 'when' remain untracked.
*/
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"what"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"who"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"what"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"who"
));
cl_git_pass
(
git_index_write
(
index
));
commit_staged_files
(
&
commit_oid
,
index
,
signature
);
git_index_free
(
index
);
...
...
tests-clar/stash/stash_helpers.c
View file @
25743bd7
...
...
@@ -46,10 +46,10 @@ void setup_stash(git_repository *repo, git_signature *signature)
cl_git_mkfile
(
"stash/.gitignore"
,
"*.ignore
\n
"
);
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"what"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"how"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"who"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
".gitignore"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"what"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"how"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"who"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
".gitignore"
));
cl_git_pass
(
git_index_write
(
index
));
commit_staged_files
(
&
commit_oid
,
index
,
signature
);
...
...
@@ -58,8 +58,8 @@ void setup_stash(git_repository *repo, git_signature *signature)
cl_git_rewritefile
(
"stash/how"
,
"not so small and
\n
"
);
/* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */
cl_git_rewritefile
(
"stash/who"
,
"funky world
\n
"
);
/* a0400d4954659306a976567af43125a0b1aa8595 */
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"what"
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"how"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"what"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"how"
));
cl_git_pass
(
git_index_write
(
index
));
cl_git_rewritefile
(
"stash/what"
,
"see you later
\n
"
);
/* bc99dc98b3eba0e9157e94769cd4d49cb49de449 */
...
...
tests-clar/status/worktree_init.c
View file @
25743bd7
...
...
@@ -38,7 +38,7 @@ void test_status_worktree_init__first_commit_in_progress(void)
cl_assert
(
result
.
status
==
GIT_STATUS_WT_NEW
);
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"testfile.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"testfile.txt"
));
cl_git_pass
(
git_index_write
(
index
));
memset
(
&
result
,
0
,
sizeof
(
result
));
...
...
@@ -172,7 +172,7 @@ void test_status_worktree_init__bracket_in_filename(void)
/* add the file to the index */
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
FILE_WITH_BRACKET
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
FILE_WITH_BRACKET
));
cl_git_pass
(
git_index_write
(
index
));
memset
(
&
result
,
0
,
sizeof
(
result
));
...
...
@@ -251,7 +251,7 @@ void test_status_worktree_init__space_in_filename(void)
/* add the file to the index */
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
FILE_WITH_SPACE
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
FILE_WITH_SPACE
));
cl_git_pass
(
git_index_write
(
index
));
memset
(
&
result
,
0
,
sizeof
(
result
));
...
...
@@ -329,7 +329,7 @@ void test_status_worktree_init__new_staged_file_must_handle_crlf(void)
cl_git_mkfile
(
"getting_started/testfile.txt"
,
"content
\r\n
"
);
// Content with CRLF
cl_git_pass
(
git_repository_index
(
&
index
,
repo
));
cl_git_pass
(
git_index_add_
from_workdir
(
index
,
"testfile.txt"
));
cl_git_pass
(
git_index_add_
bypath
(
index
,
"testfile.txt"
));
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_status_file
(
&
status
,
repo
,
"testfile.txt"
));
...
...
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