Skip to content

Commit 11047e0

Browse files
committed
Merge branch 'jk/http-backend-keep-committer-ident-env'
The smart-http backend used to always override GIT_COMMITTER_* variables with REMOTE_USER and REMOTE_ADDR. By Jeff King * jk/http-backend-keep-committer-ident-env: http-backend: respect existing GIT_COMMITTER_* variables
2 parents e5ccf5e + e32a458 commit 11047e0

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

http-backend.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "run-command.h"
88
#include "string-list.h"
99
#include "url.h"
10+
#include "argv-array.h"
1011

1112
static const char content_type[] = "Content-Type";
1213
static const char content_length[] = "Content-Length";
@@ -317,8 +318,7 @@ static void run_service(const char **argv)
317318
const char *encoding = getenv("HTTP_CONTENT_ENCODING");
318319
const char *user = getenv("REMOTE_USER");
319320
const char *host = getenv("REMOTE_ADDR");
320-
char *env[3];
321-
struct strbuf buf = STRBUF_INIT;
321+
struct argv_array env = ARGV_ARRAY_INIT;
322322
int gzipped_request = 0;
323323
struct child_process cld;
324324

@@ -332,17 +332,15 @@ static void run_service(const char **argv)
332332
if (!host || !*host)
333333
host = "(none)";
334334

335-
memset(&env, 0, sizeof(env));
336-
strbuf_addf(&buf, "GIT_COMMITTER_NAME=%s", user);
337-
env[0] = strbuf_detach(&buf, NULL);
338-
339-
strbuf_addf(&buf, "GIT_COMMITTER_EMAIL=%s@http.%s", user, host);
340-
env[1] = strbuf_detach(&buf, NULL);
341-
env[2] = NULL;
335+
if (!getenv("GIT_COMMITTER_NAME"))
336+
argv_array_pushf(&env, "GIT_COMMITTER_NAME=%s", user);
337+
if (!getenv("GIT_COMMITTER_EMAIL"))
338+
argv_array_pushf(&env, "GIT_COMMITTER_EMAIL=%s@http.%s",
339+
user, host);
342340

343341
memset(&cld, 0, sizeof(cld));
344342
cld.argv = argv;
345-
cld.env = (const char *const *)env;
343+
cld.env = env.argv;
346344
if (gzipped_request)
347345
cld.in = -1;
348346
cld.git_cmd = 1;
@@ -357,9 +355,7 @@ static void run_service(const char **argv)
357355

358356
if (finish_command(&cld))
359357
exit(1);
360-
free(env[0]);
361-
free(env[1]);
362-
strbuf_release(&buf);
358+
argv_array_clear(&env);
363359
}
364360

365361
static int show_text_ref(const char *name, const unsigned char *sha1,

t/lib-httpd/apache.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ Alias /auth/ www/auth/
5252
<Location /smart_noexport/>
5353
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
5454
</Location>
55+
<Location /smart_custom_env/>
56+
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
57+
SetEnv GIT_HTTP_EXPORT_ALL
58+
SetEnv GIT_COMMITTER_NAME "Custom User"
59+
SetEnv GIT_COMMITTER_EMAIL [email protected]
60+
</Location>
5561
ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
5662
ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
63+
ScriptAlias /smart_custom_env/ ${GIT_EXEC_PATH}/git-http-backend/
5764
<Directory ${GIT_EXEC_PATH}>
5865
Options None
5966
</Directory>

t/t5541-http-push.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test_expect_success 'setup remote repository' '
3030
git clone --bare test_repo test_repo.git &&
3131
cd test_repo.git &&
3232
git config http.receivepack true &&
33+
git config core.logallrefupdates true &&
3334
ORIG_HEAD=$(git rev-parse --verify HEAD) &&
3435
cd - &&
3536
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
@@ -222,5 +223,25 @@ test_expect_success TTY 'quiet push' '
222223
test_cmp /dev/null output
223224
'
224225

226+
test_expect_success 'http push gives sane defaults to reflog' '
227+
cd "$ROOT_PATH"/test_repo_clone &&
228+
test_commit reflog-test &&
229+
git push "$HTTPD_URL"/smart/test_repo.git &&
230+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
231+
log -g -1 --format="%gn <%ge>" >actual &&
232+
echo "anonymous <[email protected]>" >expect &&
233+
test_cmp expect actual
234+
'
235+
236+
test_expect_success 'http push respects GIT_COMMITTER_* in reflog' '
237+
cd "$ROOT_PATH"/test_repo_clone &&
238+
test_commit custom-reflog-test &&
239+
git push "$HTTPD_URL"/smart_custom_env/test_repo.git &&
240+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
241+
log -g -1 --format="%gn <%ge>" >actual &&
242+
echo "Custom User <[email protected]>" >expect &&
243+
test_cmp expect actual
244+
'
245+
225246
stop_httpd
226247
test_done

0 commit comments

Comments
 (0)