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
e07c1e1a
Commit
e07c1e1a
authored
Feb 12, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2880 from ethomson/mkdir_root
Ensure we can make a repo at the root of the filesystem
parents
5a2a5771
9cb5b0f7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
17 deletions
+65
-17
appveyor.yml
+2
-0
src/fileops.c
+18
-11
src/win32/posix_w32.c
+2
-6
tests/core/stat.c
+17
-0
tests/repo/init.c
+26
-0
No files found.
appveyor.yml
View file @
e07c1e1a
...
@@ -3,6 +3,8 @@ branches:
...
@@ -3,6 +3,8 @@ branches:
only
:
only
:
-
master
-
master
environment
:
environment
:
GITTEST_INVASIVE_FILESYSTEM
:
1
matrix
:
matrix
:
-
GENERATOR
:
"
Visual
Studio
11"
-
GENERATOR
:
"
Visual
Studio
11"
ARCH
:
32
ARCH
:
32
...
...
src/fileops.c
View file @
e07c1e1a
...
@@ -330,7 +330,7 @@ int git_futils_mkdir_withperf(
...
@@ -330,7 +330,7 @@ int git_futils_mkdir_withperf(
{
{
int
error
=
-
1
;
int
error
=
-
1
;
git_buf
make_path
=
GIT_BUF_INIT
;
git_buf
make_path
=
GIT_BUF_INIT
;
ssize_t
root
=
0
,
min_root_len
;
ssize_t
root
=
0
,
min_root_len
,
root_len
;
char
lastch
=
'/'
,
*
tail
;
char
lastch
=
'/'
,
*
tail
;
struct
stat
st
;
struct
stat
st
;
...
@@ -343,22 +343,29 @@ int git_futils_mkdir_withperf(
...
@@ -343,22 +343,29 @@ int git_futils_mkdir_withperf(
goto
done
;
goto
done
;
}
}
/* remove trailing slashes on path */
/* Trim trailing slashes (except the root) */
while
(
make_path
.
ptr
[
make_path
.
size
-
1
]
==
'/'
)
{
if
((
root_len
=
git_path_root
(
make_path
.
ptr
))
<
0
)
make_path
.
size
--
;
root_len
=
0
;
make_path
.
ptr
[
make_path
.
size
]
=
'\0'
;
else
}
root_len
++
;
while
(
make_path
.
size
>
(
size_t
)
root_len
&&
make_path
.
ptr
[
make_path
.
size
-
1
]
==
'/'
)
make_path
.
ptr
[
--
make_path
.
size
]
=
'\0'
;
/* if we are not supposed to made the last element, truncate it */
/* if we are not supposed to made the last element, truncate it */
if
((
flags
&
GIT_MKDIR_SKIP_LAST2
)
!=
0
)
{
if
((
flags
&
GIT_MKDIR_SKIP_LAST2
)
!=
0
)
{
git_
buf_rtruncate_at_char
(
&
make_path
,
'/'
);
git_
path_dirname_r
(
&
make_path
,
make_path
.
ptr
);
flags
|=
GIT_MKDIR_SKIP_LAST
;
flags
|=
GIT_MKDIR_SKIP_LAST
;
}
}
if
((
flags
&
GIT_MKDIR_SKIP_LAST
)
!=
0
)
if
((
flags
&
GIT_MKDIR_SKIP_LAST
)
!=
0
)
{
git_buf_rtruncate_at_char
(
&
make_path
,
'/'
);
git_path_dirname_r
(
&
make_path
,
make_path
.
ptr
);
}
/* if nothing left after truncation, then we're done! */
/* We were either given the root path (or trimmed it to
if
(
!
make_path
.
size
)
{
* the root), we don't have anything to do.
*/
if
(
make_path
.
size
<=
(
size_t
)
root_len
)
{
error
=
0
;
error
=
0
;
goto
done
;
goto
done
;
}
}
...
...
src/win32/posix_w32.c
View file @
e07c1e1a
...
@@ -448,12 +448,8 @@ int p_stat(const char* path, struct stat* buf)
...
@@ -448,12 +448,8 @@ int p_stat(const char* path, struct stat* buf)
git_win32_path
path_w
;
git_win32_path
path_w
;
int
len
;
int
len
;
if
((
len
=
git_win32_path_from_utf8
(
path_w
,
path
))
<
0
)
if
((
len
=
git_win32_path_from_utf8
(
path_w
,
path
))
<
0
||
return
-
1
;
lstat_w
(
path_w
,
buf
,
false
)
<
0
)
git_win32__path_trim_end
(
path_w
,
len
);
if
(
lstat_w
(
path_w
,
buf
,
false
)
<
0
)
return
-
1
;
return
-
1
;
/* The item is a symbolic link or mount point. No need to iterate
/* The item is a symbolic link or mount point. No need to iterate
...
...
tests/core/stat.c
View file @
e07c1e1a
...
@@ -95,3 +95,20 @@ void test_core_stat__0(void)
...
@@ -95,3 +95,20 @@ void test_core_stat__0(void)
cl_assert_error
(
ENOTDIR
);
cl_assert_error
(
ENOTDIR
);
}
}
void
test_core_stat__root
(
void
)
{
const
char
*
sandbox
=
clar_sandbox_path
();
git_buf
root
=
GIT_BUF_INIT
;
int
root_len
;
struct
stat
st
;
root_len
=
git_path_root
(
sandbox
);
cl_assert
(
root_len
>=
0
);
git_buf_set
(
&
root
,
sandbox
,
root_len
+
1
);
cl_must_pass
(
p_stat
(
root
.
ptr
,
&
st
));
cl_assert
(
S_ISDIR
(
st
.
st_mode
));
git_buf_free
(
&
root
);
}
tests/repo/init.c
View file @
e07c1e1a
...
@@ -714,3 +714,29 @@ void test_repo_init__init_with_initial_commit(void)
...
@@ -714,3 +714,29 @@ void test_repo_init__init_with_initial_commit(void)
git_index_free
(
index
);
git_index_free
(
index
);
}
}
void
test_repo_init__at_filesystem_root
(
void
)
{
git_repository
*
repo
;
const
char
*
sandbox
=
clar_sandbox_path
();
git_buf
root
=
GIT_BUF_INIT
;
int
root_len
;
if
(
!
cl_getenv
(
"GITTEST_INVASIVE_FILESYSTEM"
))
cl_skip
();
root_len
=
git_path_root
(
sandbox
);
cl_assert
(
root_len
>=
0
);
git_buf_put
(
&
root
,
sandbox
,
root_len
+
1
);
git_buf_joinpath
(
&
root
,
root
.
ptr
,
"libgit2_test_dir"
);
cl_assert
(
!
git_path_exists
(
root
.
ptr
));
cl_git_pass
(
git_repository_init
(
&
repo
,
root
.
ptr
,
0
));
cl_assert
(
git_path_isdir
(
root
.
ptr
));
cl_git_pass
(
git_futils_rmdir_r
(
root
.
ptr
,
NULL
,
GIT_RMDIR_REMOVE_FILES
));
git_buf_free
(
&
root
);
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