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
ea445e06
Commit
ea445e06
authored
Jul 07, 2015
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3288 from ethomson/getenv
git__getenv: utf-8 aware env reader
parents
3c831113
e069c621
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
197 additions
and
107 deletions
+197
-107
src/remote.c
+17
-8
src/sysdir.c
+22
-8
src/util.c
+48
-0
src/util.h
+5
-0
src/win32/posix_w32.c
+2
-0
tests/clar_libgit2.c
+23
-20
tests/clar_libgit2.h
+1
-0
tests/core/env.c
+7
-11
tests/core/ftruncate.c
+1
-1
tests/filter/stream.c
+1
-1
tests/online/clone.c
+53
-50
tests/online/push.c
+16
-7
tests/repo/init.c
+1
-1
No files found.
src/remote.c
View file @
ea445e06
...
@@ -153,7 +153,7 @@ static int get_check_cert(int *out, git_repository *repo)
...
@@ -153,7 +153,7 @@ static int get_check_cert(int *out, git_repository *repo)
* most specific to least specific. */
* most specific to least specific. */
/* GIT_SSL_NO_VERIFY environment variable */
/* GIT_SSL_NO_VERIFY environment variable */
if ((val = getenv("GIT_SSL_NO_VERIFY")) != NULL)
if ((val =
p_
getenv("GIT_SSL_NO_VERIFY")) != NULL)
return git_config_parse_bool(out, val);
return git_config_parse_bool(out, val);
/* http.sslVerify config setting */
/* http.sslVerify config setting */
...
@@ -759,7 +759,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
...
@@ -759,7 +759,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
{
{
git_config
*
cfg
;
git_config
*
cfg
;
git_config_entry
*
ce
=
NULL
;
git_config_entry
*
ce
=
NULL
;
const
char
*
val
=
NULL
;
git_buf
val
=
GIT_BUF_INIT
;
int
error
;
int
error
;
assert
(
remote
);
assert
(
remote
);
...
@@ -789,7 +789,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
...
@@ -789,7 +789,7 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
return
error
;
return
error
;
if
(
ce
&&
ce
->
value
)
{
if
(
ce
&&
ce
->
value
)
{
val
=
ce
->
value
;
*
proxy_url
=
git__strdup
(
ce
->
value
)
;
goto
found
;
goto
found
;
}
}
}
}
...
@@ -797,19 +797,28 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
...
@@ -797,19 +797,28 @@ int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_ur
/* http.proxy config setting */
/* http.proxy config setting */
if
((
error
=
git_config__lookup_entry
(
&
ce
,
cfg
,
"http.proxy"
,
false
))
<
0
)
if
((
error
=
git_config__lookup_entry
(
&
ce
,
cfg
,
"http.proxy"
,
false
))
<
0
)
return
error
;
return
error
;
if
(
ce
&&
ce
->
value
)
{
if
(
ce
&&
ce
->
value
)
{
val
=
ce
->
value
;
*
proxy_url
=
git__strdup
(
ce
->
value
)
;
goto
found
;
goto
found
;
}
}
/* HTTP_PROXY / HTTPS_PROXY environment variables */
/* HTTP_PROXY / HTTPS_PROXY environment variables */
val
=
use_ssl
?
getenv
(
"HTTPS_PROXY"
)
:
getenv
(
"HTTP_PROXY"
);
error
=
git__getenv
(
&
val
,
use_ssl
?
"HTTPS_PROXY"
:
"HTTP_PROXY"
);
if
(
error
<
0
)
{
if
(
error
==
GIT_ENOTFOUND
)
{
giterr_clear
();
error
=
0
;
}
return
error
;
}
*
proxy_url
=
git_buf_detach
(
&
val
);
found:
found:
if
(
val
&&
val
[
0
])
{
*
proxy_url
=
git__strdup
(
val
);
GITERR_CHECK_ALLOC
(
*
proxy_url
);
GITERR_CHECK_ALLOC
(
*
proxy_url
);
}
git_config_entry_free
(
ce
);
git_config_entry_free
(
ce
);
return
0
;
return
0
;
...
...
src/sysdir.c
View file @
ea445e06
...
@@ -29,7 +29,14 @@ static int git_sysdir_guess_global_dirs(git_buf *out)
...
@@ -29,7 +29,14 @@ static int git_sysdir_guess_global_dirs(git_buf *out)
#ifdef GIT_WIN32
#ifdef GIT_WIN32
return
git_win32__find_global_dirs
(
out
);
return
git_win32__find_global_dirs
(
out
);
#else
#else
return
git_buf_sets
(
out
,
getenv
(
"HOME"
));
int
error
=
git__getenv
(
out
,
"HOME"
);
if
(
error
==
GIT_ENOTFOUND
)
{
giterr_clear
();
error
=
0
;
}
return
error
;
#endif
#endif
}
}
...
@@ -38,15 +45,22 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
...
@@ -38,15 +45,22 @@ static int git_sysdir_guess_xdg_dirs(git_buf *out)
#ifdef GIT_WIN32
#ifdef GIT_WIN32
return
git_win32__find_xdg_dirs
(
out
);
return
git_win32__find_xdg_dirs
(
out
);
#else
#else
const
char
*
env
=
NULL
;
git_buf
env
=
GIT_BUF_INIT
;
int
error
;
if
((
env
=
getenv
(
"XDG_CONFIG_HOME"
))
!=
NULL
)
if
((
error
=
git__getenv
(
&
env
,
"XDG_CONFIG_HOME"
))
==
0
)
return
git_buf_joinpath
(
out
,
env
,
"git"
);
error
=
git_buf_joinpath
(
out
,
env
.
ptr
,
"git"
);
else
if
((
env
=
getenv
(
"HOME"
))
!=
NULL
)
return
git_buf_joinpath
(
out
,
env
,
".config/git"
);
git_buf_clear
(
out
);
if
(
error
==
GIT_ENOTFOUND
&&
(
error
=
git__getenv
(
&
env
,
"HOME"
))
==
0
)
return
0
;
error
=
git_buf_joinpath
(
out
,
env
.
ptr
,
".config/git"
);
if
(
error
==
GIT_ENOTFOUND
)
{
giterr_clear
();
error
=
0
;
}
git_buf_free
(
&
env
);
return
error
;
#endif
#endif
}
}
...
...
src/util.c
View file @
ea445e06
...
@@ -10,6 +10,10 @@
...
@@ -10,6 +10,10 @@
#include <ctype.h>
#include <ctype.h>
#include "posix.h"
#include "posix.h"
#ifdef GIT_WIN32
# include "win32/buffer.h"
#endif
#ifdef _MSC_VER
#ifdef _MSC_VER
# include <Shlwapi.h>
# include <Shlwapi.h>
#endif
#endif
...
@@ -765,3 +769,47 @@ int git__utf8_iterate(const uint8_t *str, int str_len, int32_t *dst)
...
@@ -765,3 +769,47 @@ int git__utf8_iterate(const uint8_t *str, int str_len, int32_t *dst)
*
dst
=
uc
;
*
dst
=
uc
;
return
length
;
return
length
;
}
}
#ifdef GIT_WIN32
int
git__getenv
(
git_buf
*
out
,
const
char
*
name
)
{
wchar_t
*
wide_name
=
NULL
,
*
wide_value
=
NULL
;
DWORD
value_len
;
int
error
=
-
1
;
git_buf_clear
(
out
);
if
(
git__utf8_to_16_alloc
(
&
wide_name
,
name
)
<
0
)
return
-
1
;
if
((
value_len
=
GetEnvironmentVariableW
(
wide_name
,
NULL
,
0
))
>
0
)
{
wide_value
=
git__malloc
(
value_len
*
sizeof
(
wchar_t
));
GITERR_CHECK_ALLOC
(
wide_value
);
value_len
=
GetEnvironmentVariableW
(
wide_name
,
wide_value
,
value_len
);
}
if
(
value_len
)
error
=
git_buf_put_w
(
out
,
wide_value
,
value_len
);
else
if
(
GetLastError
()
==
ERROR_ENVVAR_NOT_FOUND
)
error
=
GIT_ENOTFOUND
;
else
giterr_set
(
GITERR_OS
,
"could not read environment variable '%s'"
,
name
);
git__free
(
wide_name
);
git__free
(
wide_value
);
return
error
;
}
#else
int
git__getenv
(
git_buf
*
out
,
const
char
*
name
)
{
const
char
*
val
=
getenv
(
name
);
git_buf_clear
(
out
);
if
(
!
val
)
return
GIT_ENOTFOUND
;
return
git_buf_puts
(
out
,
val
);
}
#endif
src/util.h
View file @
ea445e06
...
@@ -7,6 +7,9 @@
...
@@ -7,6 +7,9 @@
#ifndef INCLUDE_util_h__
#ifndef INCLUDE_util_h__
#define INCLUDE_util_h__
#define INCLUDE_util_h__
#include "git2/buffer.h"
#include "buffer.h"
#if defined(GIT_MSVC_CRTDBG)
#if defined(GIT_MSVC_CRTDBG)
/* Enable MSVC CRTDBG memory leak reporting.
/* Enable MSVC CRTDBG memory leak reporting.
*
*
...
@@ -599,4 +602,6 @@ GIT_INLINE(double) git__timer(void)
...
@@ -599,4 +602,6 @@ GIT_INLINE(double) git__timer(void)
#endif
#endif
extern
int
git__getenv
(
git_buf
*
out
,
const
char
*
name
);
#endif
/* INCLUDE_util_h__ */
#endif
/* INCLUDE_util_h__ */
src/win32/posix_w32.c
View file @
ea445e06
...
@@ -11,6 +11,8 @@
...
@@ -11,6 +11,8 @@
#include "utf-conv.h"
#include "utf-conv.h"
#include "repository.h"
#include "repository.h"
#include "reparse.h"
#include "reparse.h"
#include "global.h"
#include "buffer.h"
#include <errno.h>
#include <errno.h>
#include <io.h>
#include <io.h>
#include <fcntl.h>
#include <fcntl.h>
...
...
tests/clar_libgit2.c
View file @
ea445e06
...
@@ -58,31 +58,38 @@ void cl_git_rmfile(const char *filename)
...
@@ -58,31 +58,38 @@ void cl_git_rmfile(const char *filename)
cl_must_pass
(
p_unlink
(
filename
));
cl_must_pass
(
p_unlink
(
filename
));
}
}
#ifdef GIT_WIN32
#include "win32/utf-conv.h"
char
*
cl_getenv
(
const
char
*
name
)
char
*
cl_getenv
(
const
char
*
name
)
{
{
wchar_t
*
wide_name
,
*
wide_value
;
git_buf
out
=
GIT_BUF_INIT
;
char
*
utf8_value
=
NULL
;
int
error
=
git__getenv
(
&
out
,
name
);
DWORD
value_len
;
cl_assert
(
git__utf8_to_16_alloc
(
&
wide_name
,
name
)
>=
0
);
cl_assert
(
error
>=
0
||
error
==
GIT_ENOTFOUND
);
value_len
=
GetEnvironmentVariableW
(
wide_name
,
NULL
,
0
);
if
(
error
==
GIT_ENOTFOUND
)
return
NULL
;
if
(
value_len
)
{
if
(
out
.
size
==
0
)
{
c
l_assert
(
wide_value
=
git__malloc
(
value_len
*
sizeof
(
wchar_t
))
);
c
har
*
dup
=
git__strdup
(
""
);
cl_assert
(
GetEnvironmentVariableW
(
wide_name
,
wide_value
,
value_len
)
);
cl_assert
(
dup
);
cl_assert
(
git__utf16_to_8_alloc
(
&
utf8_value
,
wide_value
)
>=
0
);
git__free
(
wide_value
)
;
return
dup
;
}
}
git__free
(
wide_name
);
return
git_buf_detach
(
&
out
);
return
utf8_value
;
}
bool
cl_is_env_set
(
const
char
*
name
)
{
char
*
env
=
cl_getenv
(
name
);
bool
result
=
(
env
!=
NULL
);
git__free
(
env
);
return
result
;
}
}
#ifdef GIT_WIN32
#include "win32/utf-conv.h"
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
{
wchar_t
*
wide_name
,
*
wide_value
=
NULL
;
wchar_t
*
wide_name
,
*
wide_value
=
NULL
;
...
@@ -138,10 +145,6 @@ int cl_rename(const char *source, const char *dest)
...
@@ -138,10 +145,6 @@ int cl_rename(const char *source, const char *dest)
#else
#else
#include <stdlib.h>
#include <stdlib.h>
char
*
cl_getenv
(
const
char
*
name
)
{
return
getenv
(
name
);
}
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
{
...
...
tests/clar_libgit2.h
View file @
ea445e06
...
@@ -119,6 +119,7 @@ bool cl_is_chmod_supported(void);
...
@@ -119,6 +119,7 @@ bool cl_is_chmod_supported(void);
/* Environment wrappers */
/* Environment wrappers */
char
*
cl_getenv
(
const
char
*
name
);
char
*
cl_getenv
(
const
char
*
name
);
bool
cl_is_env_set
(
const
char
*
name
);
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
);
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
);
/* Reliable rename */
/* Reliable rename */
...
...
tests/core/env.c
View file @
ea445e06
...
@@ -30,14 +30,8 @@ static char *home_values[] = {
...
@@ -30,14 +30,8 @@ static char *home_values[] = {
void
test_core_env__initialize
(
void
)
void
test_core_env__initialize
(
void
)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
NUM_VARS
;
++
i
)
{
for
(
i
=
0
;
i
<
NUM_VARS
;
++
i
)
const
char
*
original
=
cl_getenv
(
env_vars
[
i
]);
env_save
[
i
]
=
cl_getenv
(
env_vars
[
i
]);
#ifdef GIT_WIN32
env_save
[
i
]
=
(
char
*
)
original
;
#else
env_save
[
i
]
=
original
?
git__strdup
(
original
)
:
NULL
;
#endif
}
}
}
static
void
set_global_search_path_from_env
(
void
)
static
void
set_global_search_path_from_env
(
void
)
...
@@ -77,12 +71,14 @@ static void setenv_and_check(const char *name, const char *value)
...
@@ -77,12 +71,14 @@ static void setenv_and_check(const char *name, const char *value)
char
*
check
;
char
*
check
;
cl_git_pass
(
cl_setenv
(
name
,
value
));
cl_git_pass
(
cl_setenv
(
name
,
value
));
check
=
cl_getenv
(
name
);
check
=
cl_getenv
(
name
);
if
(
value
)
cl_assert_equal_s
(
value
,
check
);
cl_assert_equal_s
(
value
,
check
);
#ifdef GIT_WIN32
else
cl_assert
(
check
==
NULL
);
git__free
(
check
);
git__free
(
check
);
#endif
}
}
void
test_core_env__0
(
void
)
void
test_core_env__0
(
void
)
...
...
tests/core/ftruncate.c
View file @
ea445e06
...
@@ -10,7 +10,7 @@ static int fd = -1;
...
@@ -10,7 +10,7 @@ static int fd = -1;
void
test_core_ftruncate__initialize
(
void
)
void
test_core_ftruncate__initialize
(
void
)
{
{
if
(
!
cl_
getenv
(
"GITTEST_INVASIVE_FS_SIZE"
))
if
(
!
cl_
is_env_set
(
"GITTEST_INVASIVE_FS_SIZE"
))
cl_skip
();
cl_skip
();
cl_must_pass
((
fd
=
p_open
(
filename
,
O_CREAT
|
O_RDWR
,
0644
)));
cl_must_pass
((
fd
=
p_open
(
filename
,
O_CREAT
|
O_RDWR
,
0644
)));
...
...
tests/filter/stream.c
View file @
ea445e06
...
@@ -209,7 +209,7 @@ void test_filter_stream__smallfile(void)
...
@@ -209,7 +209,7 @@ void test_filter_stream__smallfile(void)
/* optionally write a 500 MB file through the compression stream */
/* optionally write a 500 MB file through the compression stream */
void
test_filter_stream__bigfile
(
void
)
void
test_filter_stream__bigfile
(
void
)
{
{
if
(
!
cl_
getenv
(
"GITTEST_INVASIVE_FS_SIZE"
))
if
(
!
cl_
is_env_set
(
"GITTEST_INVASIVE_FS_SIZE"
))
cl_skip
();
cl_skip
();
test_stream
(
51200
);
test_stream
(
51200
);
...
...
tests/online/clone.c
View file @
ea445e06
...
@@ -17,6 +17,15 @@
...
@@ -17,6 +17,15 @@
static
git_repository
*
g_repo
;
static
git_repository
*
g_repo
;
static
git_clone_options
g_options
;
static
git_clone_options
g_options
;
static
char
*
_remote_url
=
NULL
;
static
char
*
_remote_user
=
NULL
;
static
char
*
_remote_pass
=
NULL
;
static
char
*
_remote_ssh_pubkey
=
NULL
;
static
char
*
_remote_ssh_privkey
=
NULL
;
static
char
*
_remote_ssh_passphrase
=
NULL
;
static
char
*
_remote_ssh_fingerprint
=
NULL
;
void
test_online_clone__initialize
(
void
)
void
test_online_clone__initialize
(
void
)
{
{
git_checkout_options
dummy_opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
git_checkout_options
dummy_opts
=
GIT_CHECKOUT_OPTIONS_INIT
;
...
@@ -29,6 +38,14 @@ void test_online_clone__initialize(void)
...
@@ -29,6 +38,14 @@ void test_online_clone__initialize(void)
g_options
.
checkout_opts
=
dummy_opts
;
g_options
.
checkout_opts
=
dummy_opts
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
g_options
.
checkout_opts
.
checkout_strategy
=
GIT_CHECKOUT_SAFE
;
g_options
.
fetch_opts
=
dummy_fetch
;
g_options
.
fetch_opts
=
dummy_fetch
;
_remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
_remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
_remote_pass
=
cl_getenv
(
"GITTEST_REMOTE_PASS"
);
_remote_ssh_pubkey
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PUBKEY"
);
_remote_ssh_privkey
=
cl_getenv
(
"GITTEST_REMOTE_SSH_KEY"
);
_remote_ssh_passphrase
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PASSPHRASE"
);
_remote_ssh_fingerprint
=
cl_getenv
(
"GITTEST_REMOTE_SSH_FINGERPRINT"
);
}
}
void
test_online_clone__cleanup
(
void
)
void
test_online_clone__cleanup
(
void
)
...
@@ -38,6 +55,14 @@ void test_online_clone__cleanup(void)
...
@@ -38,6 +55,14 @@ void test_online_clone__cleanup(void)
g_repo
=
NULL
;
g_repo
=
NULL
;
}
}
cl_fixture_cleanup
(
"./foo"
);
cl_fixture_cleanup
(
"./foo"
);
git__free
(
_remote_url
);
git__free
(
_remote_user
);
git__free
(
_remote_pass
);
git__free
(
_remote_ssh_pubkey
);
git__free
(
_remote_ssh_privkey
);
git__free
(
_remote_ssh_passphrase
);
git__free
(
_remote_ssh_fingerprint
);
}
}
void
test_online_clone__network_full
(
void
)
void
test_online_clone__network_full
(
void
)
...
@@ -202,15 +227,12 @@ static int cred_failure_cb(
...
@@ -202,15 +227,12 @@ static int cred_failure_cb(
void
test_online_clone__cred_callback_failure_return_code_is_tunnelled
(
void
)
void
test_online_clone__cred_callback_failure_return_code_is_tunnelled
(
void
)
{
{
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
if
(
!
_remote_url
||
!
_remote_user
)
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
if
(
!
remote_url
||
!
remote_user
)
clar__skip
();
clar__skip
();
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_failure_cb
;
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_failure_cb
;
cl_git_fail_with
(
-
172
,
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
cl_git_fail_with
(
-
172
,
git_clone
(
&
g_repo
,
_
remote_url
,
"./foo"
,
&
g_options
));
}
}
static
int
cred_count_calls_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user
,
static
int
cred_count_calls_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user
,
...
@@ -233,17 +255,15 @@ static int cred_count_calls_cb(git_cred **cred, const char *url, const char *use
...
@@ -233,17 +255,15 @@ static int cred_count_calls_cb(git_cred **cred, const char *url, const char *use
void
test_online_clone__cred_callback_called_again_on_auth_failure
(
void
)
void
test_online_clone__cred_callback_called_again_on_auth_failure
(
void
)
{
{
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
size_t
counter
=
0
;
size_t
counter
=
0
;
if
(
!
remote_url
||
!
remote_user
)
if
(
!
_remote_url
||
!
_
remote_user
)
clar__skip
();
clar__skip
();
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_count_calls_cb
;
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_count_calls_cb
;
g_options
.
fetch_opts
.
callbacks
.
payload
=
&
counter
;
g_options
.
fetch_opts
.
callbacks
.
payload
=
&
counter
;
cl_git_fail_with
(
GIT_EUSER
,
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
cl_git_fail_with
(
GIT_EUSER
,
git_clone
(
&
g_repo
,
_
remote_url
,
"./foo"
,
&
g_options
));
cl_assert_equal_i
(
3
,
counter
);
cl_assert_equal_i
(
3
,
counter
);
}
}
...
@@ -269,22 +289,22 @@ void test_online_clone__credentials(void)
...
@@ -269,22 +289,22 @@ void test_online_clone__credentials(void)
/* Remote URL environment variable must be set.
/* Remote URL environment variable must be set.
* User and password are optional.
* User and password are optional.
*/
*/
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
git_cred_userpass_payload
user_pass
=
{
git_cred_userpass_payload
user_pass
=
{
cl_getenv
(
"GITTEST_REMOTE_USER"
)
,
_remote_user
,
cl_getenv
(
"GITTEST_REMOTE_PASS"
)
_remote_pass
};
};
if
(
!
remote_url
)
return
;
if
(
!
_remote_url
)
clar__skip
();
if
(
cl_
getenv
(
"GITTEST_REMOTE_DEFAULT"
))
{
if
(
cl_
is_env_set
(
"GITTEST_REMOTE_DEFAULT"
))
{
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_default
;
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_default
;
}
else
{
}
else
{
g_options
.
fetch_opts
.
callbacks
.
credentials
=
git_cred_userpass
;
g_options
.
fetch_opts
.
callbacks
.
credentials
=
git_cred_userpass
;
g_options
.
fetch_opts
.
callbacks
.
payload
=
&
user_pass
;
g_options
.
fetch_opts
.
callbacks
.
payload
=
&
user_pass
;
}
}
cl_git_pass
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_repo
,
_
remote_url
,
"./foo"
,
&
g_options
));
git_repository_free
(
g_repo
);
g_repo
=
NULL
;
git_repository_free
(
g_repo
);
g_repo
=
NULL
;
cl_fixture_cleanup
(
"./foo"
);
cl_fixture_cleanup
(
"./foo"
);
}
}
...
@@ -335,18 +355,15 @@ void test_online_clone__can_cancel(void)
...
@@ -335,18 +355,15 @@ void test_online_clone__can_cancel(void)
static
int
cred_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user_from_url
,
static
int
cred_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user_from_url
,
unsigned
int
allowed_types
,
void
*
payload
)
unsigned
int
allowed_types
,
void
*
payload
)
{
{
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
const
char
*
pubkey
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PUBKEY"
);
const
char
*
privkey
=
cl_getenv
(
"GITTEST_REMOTE_SSH_KEY"
);
const
char
*
passphrase
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PASSPHRASE"
);
GIT_UNUSED
(
url
);
GIT_UNUSED
(
user_from_url
);
GIT_UNUSED
(
payload
);
GIT_UNUSED
(
url
);
GIT_UNUSED
(
user_from_url
);
GIT_UNUSED
(
payload
);
if
(
allowed_types
&
GIT_CREDTYPE_USERNAME
)
if
(
allowed_types
&
GIT_CREDTYPE_USERNAME
)
return
git_cred_username_new
(
cred
,
remote_user
);
return
git_cred_username_new
(
cred
,
_
remote_user
);
if
(
allowed_types
&
GIT_CREDTYPE_SSH_KEY
)
if
(
allowed_types
&
GIT_CREDTYPE_SSH_KEY
)
return
git_cred_ssh_key_new
(
cred
,
remote_user
,
pubkey
,
privkey
,
passphrase
);
return
git_cred_ssh_key_new
(
cred
,
_remote_user
,
_remote_ssh_pubkey
,
_remote_ssh_privkey
,
_remote_ssh_passphrase
);
giterr_set
(
GITERR_NET
,
"unexpected cred type"
);
giterr_set
(
GITERR_NET
,
"unexpected cred type"
);
return
-
1
;
return
-
1
;
...
@@ -417,13 +434,10 @@ void test_online_clone__ssh_with_paths(void)
...
@@ -417,13 +434,10 @@ void test_online_clone__ssh_with_paths(void)
2
,
2
,
};
};
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
#ifndef GIT_SSH
#ifndef GIT_SSH
clar__skip
();
clar__skip
();
#endif
#endif
if
(
!
remote_url
||
!
remote_user
||
strncmp
(
remote_url
,
"ssh://"
,
5
)
!=
0
)
if
(
!
_remote_url
||
!
_remote_user
||
strncmp
(
_
remote_url
,
"ssh://"
,
5
)
!=
0
)
clar__skip
();
clar__skip
();
g_options
.
remote_cb
=
custom_remote_ssh_with_paths
;
g_options
.
remote_cb
=
custom_remote_ssh_with_paths
;
...
@@ -431,10 +445,10 @@ void test_online_clone__ssh_with_paths(void)
...
@@ -431,10 +445,10 @@ void test_online_clone__ssh_with_paths(void)
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_cb
;
g_options
.
fetch_opts
.
callbacks
.
credentials
=
cred_cb
;
g_options
.
fetch_opts
.
callbacks
.
payload
=
&
arr
;
g_options
.
fetch_opts
.
callbacks
.
payload
=
&
arr
;
cl_git_fail
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
cl_git_fail
(
git_clone
(
&
g_repo
,
_
remote_url
,
"./foo"
,
&
g_options
));
arr
.
strings
=
good_paths
;
arr
.
strings
=
good_paths
;
cl_git_pass
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_repo
,
_
remote_url
,
"./foo"
,
&
g_options
));
}
}
static
int
cred_foo_bar
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
username_from_url
,
static
int
cred_foo_bar
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
username_from_url
,
...
@@ -460,15 +474,13 @@ int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *pay
...
@@ -460,15 +474,13 @@ int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *pay
{
{
git_cert_hostkey
*
key
;
git_cert_hostkey
*
key
;
git_oid
expected
=
{{
0
}},
actual
=
{{
0
}};
git_oid
expected
=
{{
0
}},
actual
=
{{
0
}};
const
char
*
expected_str
;
GIT_UNUSED
(
valid
);
GIT_UNUSED
(
valid
);
GIT_UNUSED
(
payload
);
GIT_UNUSED
(
payload
);
expected_str
=
cl_getenv
(
"GITTEST_REMOTE_SSH_FINGERPRINT"
);
cl_assert
(
_remote_ssh_fingerprint
);
cl_assert
(
expected_str
);
cl_git_pass
(
git_oid_fromstrp
(
&
expected
,
expected_str
));
cl_git_pass
(
git_oid_fromstrp
(
&
expected
,
_remote_ssh_fingerprint
));
cl_assert_equal_i
(
GIT_CERT_HOSTKEY_LIBSSH2
,
cert
->
cert_type
);
cl_assert_equal_i
(
GIT_CERT_HOSTKEY_LIBSSH2
,
cert
->
cert_type
);
key
=
(
git_cert_hostkey
*
)
cert
;
key
=
(
git_cert_hostkey
*
)
cert
;
...
@@ -477,9 +489,9 @@ int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *pay
...
@@ -477,9 +489,9 @@ int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *pay
* the type. Here we abuse the fact that both hashes fit into
* the type. Here we abuse the fact that both hashes fit into
* our git_oid type.
* our git_oid type.
*/
*/
if
(
strlen
(
expected_str
)
==
32
&&
key
->
type
&
GIT_CERT_SSH_MD5
)
{
if
(
strlen
(
_remote_ssh_fingerprint
)
==
32
&&
key
->
type
&
GIT_CERT_SSH_MD5
)
{
memcpy
(
&
actual
.
id
,
key
->
hash_md5
,
16
);
memcpy
(
&
actual
.
id
,
key
->
hash_md5
,
16
);
}
else
if
(
strlen
(
expected_str
)
==
40
&&
key
->
type
&
GIT_CERT_SSH_SHA1
)
{
}
else
if
(
strlen
(
_remote_ssh_fingerprint
)
==
40
&&
key
->
type
&
GIT_CERT_SSH_SHA1
)
{
memcpy
(
&
actual
,
key
->
hash_sha1
,
20
);
memcpy
(
&
actual
,
key
->
hash_sha1
,
20
);
}
else
{
}
else
{
cl_fail
(
"Cannot find a usable SSH hash"
);
cl_fail
(
"Cannot find a usable SSH hash"
);
...
@@ -496,7 +508,7 @@ void test_online_clone__ssh_cert(void)
...
@@ -496,7 +508,7 @@ void test_online_clone__ssh_cert(void)
{
{
g_options
.
fetch_opts
.
callbacks
.
certificate_check
=
ssh_certificate_check
;
g_options
.
fetch_opts
.
callbacks
.
certificate_check
=
ssh_certificate_check
;
if
(
!
cl_getenv
(
"GITTEST_REMOTE_SSH_FINGERPRINT"
)
)
if
(
!
_remote_ssh_fingerprint
)
cl_skip
();
cl_skip
();
cl_git_fail_with
(
GIT_EUSER
,
git_clone
(
&
g_repo
,
"ssh://localhost/foo"
,
"./foo"
,
&
g_options
));
cl_git_fail_with
(
GIT_EUSER
,
git_clone
(
&
g_repo
,
"ssh://localhost/foo"
,
"./foo"
,
&
g_options
));
...
@@ -525,22 +537,17 @@ static char *read_key_file(const char *path)
...
@@ -525,22 +537,17 @@ static char *read_key_file(const char *path)
static
int
ssh_memory_cred_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user_from_url
,
static
int
ssh_memory_cred_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user_from_url
,
unsigned
int
allowed_types
,
void
*
payload
)
unsigned
int
allowed_types
,
void
*
payload
)
{
{
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
const
char
*
pubkey_path
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PUBKEY"
);
const
char
*
privkey_path
=
cl_getenv
(
"GITTEST_REMOTE_SSH_KEY"
);
const
char
*
passphrase
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PASSPHRASE"
);
GIT_UNUSED
(
url
);
GIT_UNUSED
(
user_from_url
);
GIT_UNUSED
(
payload
);
GIT_UNUSED
(
url
);
GIT_UNUSED
(
user_from_url
);
GIT_UNUSED
(
payload
);
if
(
allowed_types
&
GIT_CREDTYPE_USERNAME
)
if
(
allowed_types
&
GIT_CREDTYPE_USERNAME
)
return
git_cred_username_new
(
cred
,
remote_user
);
return
git_cred_username_new
(
cred
,
_
remote_user
);
if
(
allowed_types
&
GIT_CREDTYPE_SSH_KEY
)
if
(
allowed_types
&
GIT_CREDTYPE_SSH_KEY
)
{
{
char
*
pubkey
=
read_key_file
(
pubkey_path
);
char
*
pubkey
=
read_key_file
(
_remote_ssh_pubkey
);
char
*
privkey
=
read_key_file
(
privkey_path
);
char
*
privkey
=
read_key_file
(
_remote_ssh_privkey
);
int
ret
=
git_cred_ssh_key_memory_new
(
cred
,
remote_user
,
pubkey
,
privkey
,
passphrase
);
int
ret
=
git_cred_ssh_key_memory_new
(
cred
,
_remote_user
,
pubkey
,
privkey
,
_remote_ssh_
passphrase
);
if
(
privkey
)
if
(
privkey
)
free
(
privkey
);
free
(
privkey
);
...
@@ -555,19 +562,15 @@ static int ssh_memory_cred_cb(git_cred **cred, const char *url, const char *user
...
@@ -555,19 +562,15 @@ static int ssh_memory_cred_cb(git_cred **cred, const char *url, const char *user
void
test_online_clone__ssh_memory_auth
(
void
)
void
test_online_clone__ssh_memory_auth
(
void
)
{
{
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
const
char
*
privkey
=
cl_getenv
(
"GITTEST_REMOTE_SSH_KEY"
);
#ifndef GIT_SSH_MEMORY_CREDENTIALS
#ifndef GIT_SSH_MEMORY_CREDENTIALS
clar__skip
();
clar__skip
();
#endif
#endif
if
(
!
remote_url
||
!
remote_user
||
!
privkey
||
strncmp
(
remote_url
,
"ssh://"
,
5
)
!=
0
)
if
(
!
_remote_url
||
!
_remote_user
||
!
_remote_ssh_privkey
||
strncmp
(
_
remote_url
,
"ssh://"
,
5
)
!=
0
)
clar__skip
();
clar__skip
();
g_options
.
fetch_opts
.
callbacks
.
credentials
=
ssh_memory_cred_cb
;
g_options
.
fetch_opts
.
callbacks
.
credentials
=
ssh_memory_cred_cb
;
cl_git_pass
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
cl_git_pass
(
git_clone
(
&
g_repo
,
_
remote_url
,
"./foo"
,
&
g_options
));
}
}
void
test_online_clone__url_with_no_path_returns_EINVALIDSPEC
(
void
)
void
test_online_clone__url_with_no_path_returns_EINVALIDSPEC
(
void
)
...
...
tests/online/push.c
View file @
ea445e06
...
@@ -9,16 +9,16 @@
...
@@ -9,16 +9,16 @@
static
git_repository
*
_repo
;
static
git_repository
*
_repo
;
static
char
*
_remote_url
;
static
char
*
_remote_url
=
NULL
;
static
char
*
_remote_ssh_key
;
static
char
*
_remote_user
=
NULL
;
static
char
*
_remote_ssh_pubkey
;
static
char
*
_remote_pass
=
NULL
;
static
char
*
_remote_ssh_passphrase
;
static
char
*
_remote_user
;
static
char
*
_remote_ssh_key
=
NULL
;
static
char
*
_remote_pass
;
static
char
*
_remote_ssh_pubkey
=
NULL
;
static
char
*
_remote_ssh_passphrase
=
NULL
;
static
char
*
_remote_default
;
static
char
*
_remote_default
=
NULL
;
static
int
cred_acquire_cb
(
git_cred
**
,
const
char
*
,
const
char
*
,
unsigned
int
,
void
*
);
static
int
cred_acquire_cb
(
git_cred
**
,
const
char
*
,
const
char
*
,
unsigned
int
,
void
*
);
...
@@ -355,6 +355,7 @@ void test_online_push__initialize(void)
...
@@ -355,6 +355,7 @@ void test_online_push__initialize(void)
git_oid_fromstr
(
&
_tag_tag
,
"eea4f2705eeec2db3813f2430829afce99cd00b5"
);
git_oid_fromstr
(
&
_tag_tag
,
"eea4f2705eeec2db3813f2430829afce99cd00b5"
);
/* Remote URL environment variable must be set. User and password are optional. */
/* Remote URL environment variable must be set. User and password are optional. */
_remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
_remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
_remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
_remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
_remote_pass
=
cl_getenv
(
"GITTEST_REMOTE_PASS"
);
_remote_pass
=
cl_getenv
(
"GITTEST_REMOTE_PASS"
);
...
@@ -406,6 +407,14 @@ void test_online_push__cleanup(void)
...
@@ -406,6 +407,14 @@ void test_online_push__cleanup(void)
git_remote_free
(
_remote
);
git_remote_free
(
_remote
);
_remote
=
NULL
;
_remote
=
NULL
;
git__free
(
_remote_url
);
git__free
(
_remote_user
);
git__free
(
_remote_pass
);
git__free
(
_remote_ssh_key
);
git__free
(
_remote_ssh_pubkey
);
git__free
(
_remote_ssh_passphrase
);
git__free
(
_remote_default
);
/* Freed by cl_git_sandbox_cleanup */
/* Freed by cl_git_sandbox_cleanup */
_repo
=
NULL
;
_repo
=
NULL
;
...
...
tests/repo/init.c
View file @
ea445e06
...
@@ -713,7 +713,7 @@ void test_repo_init__at_filesystem_root(void)
...
@@ -713,7 +713,7 @@ void test_repo_init__at_filesystem_root(void)
git_buf
root
=
GIT_BUF_INIT
;
git_buf
root
=
GIT_BUF_INIT
;
int
root_len
;
int
root_len
;
if
(
!
cl_
getenv
(
"GITTEST_INVASIVE_FS_STRUCTURE"
))
if
(
!
cl_
is_env_set
(
"GITTEST_INVASIVE_FS_STRUCTURE"
))
cl_skip
();
cl_skip
();
root_len
=
git_path_root
(
sandbox
);
root_len
=
git_path_root
(
sandbox
);
...
...
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