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
5692dcf1
Commit
5692dcf1
authored
Dec 24, 2014
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2772 from ethomson/case_changing_rename
Case changing rename
parents
171c2ff1
40d79154
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
14 deletions
+83
-14
CHANGELOG.md
+3
-0
src/checkout.c
+1
-1
tests/checkout/tree.c
+79
-13
No files found.
CHANGELOG.md
View file @
5692dcf1
...
@@ -145,3 +145,6 @@ v0.21 + 1
...
@@ -145,3 +145,6 @@ v0.21 + 1
*
git_treebuilder_create now takes a repository so that it can query
*
git_treebuilder_create now takes a repository so that it can query
repository configuration. Subsequently, git_treebuilder_write no
repository configuration. Subsequently, git_treebuilder_write no
longer takes a repository.
longer takes a repository.
*
git_checkout now handles case-changing renames correctly on
case-insensitive filesystems; for example renaming "readme" to "README".
src/checkout.c
View file @
5692dcf1
...
@@ -2474,7 +2474,7 @@ int git_checkout_tree(
...
@@ -2474,7 +2474,7 @@ int git_checkout_tree(
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
)
if
((
error
=
git_repository_index
(
&
index
,
repo
))
<
0
)
return
error
;
return
error
;
if
(
!
(
error
=
git_iterator_for_tree
(
&
tree_i
,
tree
,
0
,
NULL
,
NULL
)))
if
(
!
(
error
=
git_iterator_for_tree
(
&
tree_i
,
tree
,
GIT_ITERATOR_DONT_IGNORE_CASE
,
NULL
,
NULL
)))
error
=
git_checkout_iterator
(
tree_i
,
index
,
opts
);
error
=
git_checkout_iterator
(
tree_i
,
index
,
opts
);
git_iterator_free
(
tree_i
);
git_iterator_free
(
tree_i
);
...
...
tests/checkout/tree.c
View file @
5692dcf1
...
@@ -645,14 +645,7 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void)
...
@@ -645,14 +645,7 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void)
cl_git_fail_with
(
git_checkout_tree
(
g_repo
,
obj
,
&
opts
),
-
5555
);
cl_git_fail_with
(
git_checkout_tree
(
g_repo
,
obj
,
&
opts
),
-
5555
);
cl_assert
(
!
git_path_exists
(
"testrepo/new.txt"
));
cl_assert
(
!
git_path_exists
(
"testrepo/new.txt"
));
cl_assert_equal_i
(
4
,
ca
.
count
);
/* on case-insensitive FS = a/b.txt, branch_file.txt, new.txt */
/* on case-sensitive FS = README, then above */
if
(
git_path_exists
(
"testrepo/.git/CoNfIg"
))
/* case insensitive */
cl_assert_equal_i
(
3
,
ca
.
count
);
else
cl_assert_equal_i
(
4
,
ca
.
count
);
/* and again with a different stopping point and return code */
/* and again with a different stopping point and return code */
ca
.
filename
=
"README"
;
ca
.
filename
=
"README"
;
...
@@ -662,11 +655,7 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void)
...
@@ -662,11 +655,7 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void)
cl_git_fail_with
(
git_checkout_tree
(
g_repo
,
obj
,
&
opts
),
123
);
cl_git_fail_with
(
git_checkout_tree
(
g_repo
,
obj
,
&
opts
),
123
);
cl_assert
(
!
git_path_exists
(
"testrepo/new.txt"
));
cl_assert
(
!
git_path_exists
(
"testrepo/new.txt"
));
cl_assert_equal_i
(
1
,
ca
.
count
);
if
(
git_path_exists
(
"testrepo/.git/CoNfIg"
))
/* case insensitive */
cl_assert_equal_i
(
4
,
ca
.
count
);
else
cl_assert_equal_i
(
1
,
ca
.
count
);
git_object_free
(
obj
);
git_object_free
(
obj
);
}
}
...
@@ -1034,3 +1023,80 @@ void test_checkout_tree__removes_conflicts_only_by_pathscope(void)
...
@@ -1034,3 +1023,80 @@ void test_checkout_tree__removes_conflicts_only_by_pathscope(void)
git_commit_free
(
commit
);
git_commit_free
(
commit
);
git_index_free
(
index
);
git_index_free
(
index
);
}
}
void
test_checkout_tree__case_changing_rename
(
void
)
{
git_index
*
index
;
git_checkout_options
opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_oid
master_id
,
dir_commit_id
,
tree_id
,
commit_id
;
git_commit
*
master_commit
,
*
dir_commit
;
git_tree
*
tree
;
git_signature
*
signature
;
const
git_index_entry
*
index_entry
;
bool
case_sensitive
;
assert_on_branch
(
g_repo
,
"master"
);
cl_git_pass
(
git_repository_index
(
&
index
,
g_repo
));
/* Switch branches and perform a case-changing rename */
opts
.
checkout_strategy
=
GIT_CHECKOUT_FORCE
;
cl_git_pass
(
git_reference_name_to_id
(
&
dir_commit_id
,
g_repo
,
"refs/heads/dir"
));
cl_git_pass
(
git_commit_lookup
(
&
dir_commit
,
g_repo
,
&
dir_commit_id
));
cl_git_pass
(
git_checkout_tree
(
g_repo
,
(
git_object
*
)
dir_commit
,
&
opts
));
cl_git_pass
(
git_repository_set_head
(
g_repo
,
"refs/heads/dir"
,
NULL
,
NULL
));
cl_assert
(
git_path_isfile
(
"testrepo/README"
));
case_sensitive
=
!
git_path_isfile
(
"testrepo/readme"
);
cl_assert
(
index_entry
=
git_index_get_bypath
(
index
,
"README"
,
0
));
cl_assert_equal_s
(
"README"
,
index_entry
->
path
);
cl_git_pass
(
git_index_remove_bypath
(
index
,
"README"
));
cl_git_pass
(
p_rename
(
"testrepo/README"
,
"testrepo/__readme__"
));
cl_git_pass
(
p_rename
(
"testrepo/__readme__"
,
"testrepo/readme"
));
cl_git_append2file
(
"testrepo/readme"
,
"An addendum..."
);
cl_git_pass
(
git_index_add_bypath
(
index
,
"readme"
));
cl_git_pass
(
git_index_write
(
index
));
cl_git_pass
(
git_index_write_tree
(
&
tree_id
,
index
));
cl_git_pass
(
git_tree_lookup
(
&
tree
,
g_repo
,
&
tree_id
));
cl_git_pass
(
git_signature_new
(
&
signature
,
"Renamer"
,
"rename@contoso.com"
,
time
(
NULL
),
0
));
cl_git_pass
(
git_commit_create
(
&
commit_id
,
g_repo
,
"refs/heads/dir"
,
signature
,
signature
,
NULL
,
"case-changing rename"
,
tree
,
1
,
(
const
git_commit
**
)
&
dir_commit
));
cl_assert
(
git_path_isfile
(
"testrepo/readme"
));
if
(
case_sensitive
)
cl_assert
(
!
git_path_isfile
(
"testrepo/README"
));
cl_assert
(
index_entry
=
git_index_get_bypath
(
index
,
"readme"
,
0
));
cl_assert_equal_s
(
"readme"
,
index_entry
->
path
);
/* Switching back to master should rename readme -> README */
opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
cl_git_pass
(
git_reference_name_to_id
(
&
master_id
,
g_repo
,
"refs/heads/master"
));
cl_git_pass
(
git_commit_lookup
(
&
master_commit
,
g_repo
,
&
master_id
));
cl_git_pass
(
git_checkout_tree
(
g_repo
,
(
git_object
*
)
master_commit
,
&
opts
));
cl_git_pass
(
git_repository_set_head
(
g_repo
,
"refs/heads/master"
,
NULL
,
NULL
));
assert_on_branch
(
g_repo
,
"master"
);
cl_assert
(
git_path_isfile
(
"testrepo/README"
));
if
(
case_sensitive
)
cl_assert
(
!
git_path_isfile
(
"testrepo/readme"
));
cl_assert
(
index_entry
=
git_index_get_bypath
(
index
,
"README"
,
0
));
cl_assert_equal_s
(
"README"
,
index_entry
->
path
);
git_signature_free
(
signature
);
git_tree_free
(
tree
);
git_commit_free
(
dir_commit
);
git_commit_free
(
master_commit
);
}
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