Merge branch 'jk/http-backend-keep-committer-ident-env' into maint
By Jeff King * jk/http-backend-keep-committer-ident-env: http-backend: respect existing GIT_COMMITTER_* variables Conflicts: t/t5541-http-push.sh
This commit is contained in:
commit
8cde60210d
@ -7,6 +7,7 @@
|
|||||||
#include "run-command.h"
|
#include "run-command.h"
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "url.h"
|
#include "url.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
|
||||||
static const char content_type[] = "Content-Type";
|
static const char content_type[] = "Content-Type";
|
||||||
static const char content_length[] = "Content-Length";
|
static const char content_length[] = "Content-Length";
|
||||||
@ -317,8 +318,7 @@ static void run_service(const char **argv)
|
|||||||
const char *encoding = getenv("HTTP_CONTENT_ENCODING");
|
const char *encoding = getenv("HTTP_CONTENT_ENCODING");
|
||||||
const char *user = getenv("REMOTE_USER");
|
const char *user = getenv("REMOTE_USER");
|
||||||
const char *host = getenv("REMOTE_ADDR");
|
const char *host = getenv("REMOTE_ADDR");
|
||||||
char *env[3];
|
struct argv_array env = ARGV_ARRAY_INIT;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
|
||||||
int gzipped_request = 0;
|
int gzipped_request = 0;
|
||||||
struct child_process cld;
|
struct child_process cld;
|
||||||
|
|
||||||
@ -332,17 +332,15 @@ static void run_service(const char **argv)
|
|||||||
if (!host || !*host)
|
if (!host || !*host)
|
||||||
host = "(none)";
|
host = "(none)";
|
||||||
|
|
||||||
memset(&env, 0, sizeof(env));
|
if (!getenv("GIT_COMMITTER_NAME"))
|
||||||
strbuf_addf(&buf, "GIT_COMMITTER_NAME=%s", user);
|
argv_array_pushf(&env, "GIT_COMMITTER_NAME=%s", user);
|
||||||
env[0] = strbuf_detach(&buf, NULL);
|
if (!getenv("GIT_COMMITTER_EMAIL"))
|
||||||
|
argv_array_pushf(&env, "GIT_COMMITTER_EMAIL=%s@http.%s",
|
||||||
strbuf_addf(&buf, "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
|
user, host);
|
||||||
env[1] = strbuf_detach(&buf, NULL);
|
|
||||||
env[2] = NULL;
|
|
||||||
|
|
||||||
memset(&cld, 0, sizeof(cld));
|
memset(&cld, 0, sizeof(cld));
|
||||||
cld.argv = argv;
|
cld.argv = argv;
|
||||||
cld.env = (const char *const *)env;
|
cld.env = env.argv;
|
||||||
if (gzipped_request)
|
if (gzipped_request)
|
||||||
cld.in = -1;
|
cld.in = -1;
|
||||||
cld.git_cmd = 1;
|
cld.git_cmd = 1;
|
||||||
@ -357,9 +355,7 @@ static void run_service(const char **argv)
|
|||||||
|
|
||||||
if (finish_command(&cld))
|
if (finish_command(&cld))
|
||||||
exit(1);
|
exit(1);
|
||||||
free(env[0]);
|
argv_array_clear(&env);
|
||||||
free(env[1]);
|
|
||||||
strbuf_release(&buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int show_text_ref(const char *name, const unsigned char *sha1,
|
static int show_text_ref(const char *name, const unsigned char *sha1,
|
||||||
|
@ -52,8 +52,15 @@ Alias /auth/ www/auth/
|
|||||||
<Location /smart_noexport/>
|
<Location /smart_noexport/>
|
||||||
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
|
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
|
||||||
</Location>
|
</Location>
|
||||||
|
<Location /smart_custom_env/>
|
||||||
|
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
|
||||||
|
SetEnv GIT_HTTP_EXPORT_ALL
|
||||||
|
SetEnv GIT_COMMITTER_NAME "Custom User"
|
||||||
|
SetEnv GIT_COMMITTER_EMAIL custom@example.com
|
||||||
|
</Location>
|
||||||
ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
|
ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
|
||||||
ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
|
ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
|
||||||
|
ScriptAlias /smart_custom_env/ ${GIT_EXEC_PATH}/git-http-backend/
|
||||||
<Directory ${GIT_EXEC_PATH}>
|
<Directory ${GIT_EXEC_PATH}>
|
||||||
Options None
|
Options None
|
||||||
</Directory>
|
</Directory>
|
||||||
|
@ -30,6 +30,7 @@ test_expect_success 'setup remote repository' '
|
|||||||
git clone --bare test_repo test_repo.git &&
|
git clone --bare test_repo test_repo.git &&
|
||||||
cd test_repo.git &&
|
cd test_repo.git &&
|
||||||
git config http.receivepack true &&
|
git config http.receivepack true &&
|
||||||
|
git config core.logallrefupdates true &&
|
||||||
ORIG_HEAD=$(git rev-parse --verify HEAD) &&
|
ORIG_HEAD=$(git rev-parse --verify HEAD) &&
|
||||||
cd - &&
|
cd - &&
|
||||||
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
|
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
|
||||||
@ -245,5 +246,25 @@ test_expect_success 'push --progress shows progress to non-tty' '
|
|||||||
grep "^Writing objects" output
|
grep "^Writing objects" output
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'http push gives sane defaults to reflog' '
|
||||||
|
cd "$ROOT_PATH"/test_repo_clone &&
|
||||||
|
test_commit reflog-test &&
|
||||||
|
git push "$HTTPD_URL"/smart/test_repo.git &&
|
||||||
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
|
||||||
|
log -g -1 --format="%gn <%ge>" >actual &&
|
||||||
|
echo "anonymous <anonymous@http.127.0.0.1>" >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
|
||||||
|
cd "$ROOT_PATH"/test_repo_clone &&
|
||||||
|
test_commit custom-reflog-test &&
|
||||||
|
git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
|
||||||
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
|
||||||
|
log -g -1 --format="%gn <%ge>" >actual &&
|
||||||
|
echo "Custom User <custom@example.com>" >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
stop_httpd
|
stop_httpd
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user