Skip to content

Commit d9f39d9

Browse files
committed
Merge branch 'maint'
* maint: gitweb: Fix 'history' view for deleted files with history Document that WebDAV doesn't need git on the server, and works over SSL git-remote: reject adding remotes with invalid names am: POSIX portability fix
2 parents 9a49e00 + 5634cf2 commit d9f39d9

File tree

8 files changed

+97
-22
lines changed

8 files changed

+97
-22
lines changed

Documentation/howto/setup-git-server-over-http.txt

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
From: Rutger Nijlunsing <[email protected]>
2-
Subject: Setting up a git repository which can be pushed into and pulled from over HTTP.
2+
Subject: Setting up a git repository which can be pushed into and pulled from over HTTP(S).
33
Date: Thu, 10 Aug 2006 22:00:26 +0200
44

55
Since Apache is one of those packages people like to compile
@@ -40,19 +40,23 @@ What's needed:
4040

4141
- have permissions to chown a directory
4242

43-
- have git installed at the server _and_ client
43+
- have git installed on the client, and
4444

45-
In effect, this probably means you're going to be root.
45+
- either have git installed on the server or have a webdav client on
46+
the client.
47+
48+
In effect, this means you're going to be root, or that you're using a
49+
preconfigured WebDAV server.
4650

4751

4852
Step 1: setup a bare GIT repository
4953
-----------------------------------
5054

5155
At the time of writing, git-http-push cannot remotely create a GIT
5256
repository. So we have to do that at the server side with git. Another
53-
option would be to generate an empty repository at the client and copy
54-
it to the server with WebDAV. But then you're probably the first to
55-
try that out :)
57+
option is to generate an empty bare repository at the client and copy
58+
it to the server with a WebDAV client (which is the only option if Git
59+
is not installed on the server).
5660

5761
Create the directory under the DocumentRoot of the directories served
5862
by Apache. As an example we take /usr/local/apache2, but try "grep
@@ -169,7 +173,9 @@ On Debian:
169173

170174
Most tests should pass.
171175

172-
A command line tool to test WebDAV is cadaver.
176+
A command line tool to test WebDAV is cadaver. If you prefer GUIs, for
177+
example, konqueror can open WebDAV URLs as "webdav://..." or
178+
"webdavs://...".
173179

174180
If you're into Windows, from XP onwards Internet Explorer supports
175181
WebDAV. For this, do Internet Explorer -> Open Location ->
@@ -179,8 +185,9 @@ http://<servername>/my-new-repo.git [x] Open as webfolder -> login .
179185
Step 3: setup the client
180186
------------------------
181187

182-
Make sure that you have HTTP support, i.e. your git was built with curl.
183-
The easiest way to check is to look for the executable 'git-http-push'.
188+
Make sure that you have HTTP support, i.e. your git was built with
189+
curl (version more recent than 7.10). The command 'git http-push' with
190+
no argument should display a usage message.
184191

185192
Then, add the following to your $HOME/.netrc (you can do without, but will be
186193
asked to input your password a _lot_ of times):
@@ -197,10 +204,10 @@ instead of the server name.
197204

198205
To check whether all is OK, do:
199206

200-
curl --netrc --location -v http://<username>@<servername>/my-new-repo.git/
201-
202-
...this should give a directory listing in HTML of /var/www/my-new-repo.git .
207+
curl --netrc --location -v http://<username>@<servername>/my-new-repo.git/HEAD
203208

209+
...this should give something like 'ref: refs/heads/master', which is
210+
the content of the file HEAD on the server.
204211

205212
Now, add the remote in your existing repository which contains the project
206213
you want to export:
@@ -225,6 +232,15 @@ want to export) to repository called 'upload', which we previously
225232
defined with git-config.
226233

227234

235+
Using a proxy:
236+
--------------
237+
238+
If you have to access the WebDAV server from behind an HTTP(S) proxy,
239+
set the variable 'all_proxy' to 'http://proxy-host.com:port', or
240+
'http://login-on-proxy:[email protected]:port'. See 'man
241+
curl' for details.
242+
243+
228244
Troubleshooting:
229245
----------------
230246

@@ -248,9 +264,14 @@ Reading /usr/local/apache2/logs/error_log is often helpful.
248264

249265
On Debian: Read /var/log/apache2/error.log instead.
250266

267+
If you access HTTPS locations, git may fail verifying the SSL
268+
certificate (this is return code 60). Setting http.sslVerify=false can
269+
help diagnosing the problem, but removes security checks.
270+
251271

252272
Debian References: http://www.debian-administration.org/articles/285
253273

254274
Authors
255275
Johannes Schindelin <[email protected]>
256276
Rutger Nijlunsing <[email protected]>
277+
Matthieu Moy <[email protected]>

builtin-remote.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,22 @@ static int add(int argc, const char **argv)
8888
strbuf_init(&buf, 0);
8989
strbuf_init(&buf2, 0);
9090

91+
strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name);
92+
if (!valid_fetch_refspec(buf2.buf))
93+
die("'%s' is not a valid remote name", name);
94+
9195
strbuf_addf(&buf, "remote.%s.url", name);
9296
if (git_config_set(buf.buf, url))
9397
return 1;
9498

99+
strbuf_reset(&buf);
100+
strbuf_addf(&buf, "remote.%s.fetch", name);
101+
95102
if (track.nr == 0)
96103
path_list_append("*", &track);
97104
for (i = 0; i < track.nr; i++) {
98105
struct path_list_item *item = track.items + i;
99106

100-
strbuf_reset(&buf);
101-
strbuf_addf(&buf, "remote.%s.fetch", name);
102-
103107
strbuf_reset(&buf2);
104108
if (mirror)
105109
strbuf_addf(&buf2, "refs/%s:refs/%s",

git-am.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ do
330330
SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
331331
case "$keep_subject" in -k) SUBJECT="[PATCH] $SUBJECT" ;; esac
332332

333-
(echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
333+
(printf '%s\n\n' "$SUBJECT"; cat "$dotest/msg") |
334334
git stripspace > "$dotest/msg-clean"
335335
;;
336336
esac

gitweb/gitweb.perl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5176,14 +5176,26 @@ sub git_history {
51765176
my $refs = git_get_references();
51775177
my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
51785178

5179+
my @commitlist = parse_commits($hash_base, 101, (100 * $page),
5180+
$file_name, "--full-history");
5181+
if (!@commitlist) {
5182+
die_error('404 Not Found', "No such file or directory on given branch");
5183+
}
5184+
51795185
if (!defined $hash && defined $file_name) {
5180-
$hash = git_get_hash_by_path($hash_base, $file_name);
5186+
# some commits could have deleted file in question,
5187+
# and not have it in tree, but one of them has to have it
5188+
for (my $i = 0; $i <= @commitlist; $i++) {
5189+
$hash = git_get_hash_by_path($commitlist[$i]{'id'}, $file_name);
5190+
last if defined $hash;
5191+
}
51815192
}
51825193
if (defined $hash) {
51835194
$ftype = git_get_type($hash);
51845195
}
5185-
5186-
my @commitlist = parse_commits($hash_base, 101, (100 * $page), $file_name, "--full-history");
5196+
if (!defined $ftype) {
5197+
die_error(undef, "Unknown type of object");
5198+
}
51875199

51885200
my $paging_nav = '';
51895201
if ($page > 0) {

remote.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ static void read_config(void)
409409
alias_all_urls();
410410
}
411411

412-
static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch)
412+
static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify)
413413
{
414414
int i;
415415
int st;
@@ -519,17 +519,32 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
519519
return rs;
520520

521521
invalid:
522+
if (verify) {
523+
free(rs);
524+
return NULL;
525+
}
522526
die("Invalid refspec '%s'", refspec[i]);
523527
}
524528

529+
int valid_fetch_refspec(const char *fetch_refspec_str)
530+
{
531+
const char *fetch_refspec[] = { fetch_refspec_str };
532+
struct refspec *refspec;
533+
534+
refspec = parse_refspec_internal(1, fetch_refspec, 1, 1);
535+
if (refspec)
536+
free(refspec);
537+
return !!refspec;
538+
}
539+
525540
struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec)
526541
{
527-
return parse_refspec_internal(nr_refspec, refspec, 1);
542+
return parse_refspec_internal(nr_refspec, refspec, 1, 0);
528543
}
529544

530545
struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
531546
{
532-
return parse_refspec_internal(nr_refspec, refspec, 0);
547+
return parse_refspec_internal(nr_refspec, refspec, 0, 0);
533548
}
534549

535550
static int valid_remote_nick(const char *name)

remote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ void free_refs(struct ref *ref);
6767
*/
6868
void ref_remove_duplicates(struct ref *ref_map);
6969

70+
int valid_fetch_refspec(const char *refspec);
7071
struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec);
7172
struct refspec *parse_push_refspec(int nr_refspec, const char **refspec);
7273

t/t5505-remote.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,10 @@ test_expect_success '"remote show" does not show symbolic refs' '
253253
254254
'
255255

256+
test_expect_success 'reject adding remote with an invalid name' '
257+
258+
! git remote add some:url desired-name
259+
260+
'
261+
256262
test_done

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,22 @@ test_expect_success \
483483
'gitweb_run "p=.git;a=history;f=file"'
484484
test_debug 'cat gitweb.log'
485485

486+
test_expect_success \
487+
'logs: history (implicit HEAD, non-existent file)' \
488+
'gitweb_run "p=.git;a=history;f=non-existent"'
489+
test_debug 'cat gitweb.log'
490+
491+
test_expect_success \
492+
'logs: history (implicit HEAD, deleted file)' \
493+
'git checkout master &&
494+
echo "to be deleted" > deleted_file &&
495+
git add deleted_file &&
496+
git commit -m "Add file to be deleted" &&
497+
git rm deleted_file &&
498+
git commit -m "Delete file" &&
499+
gitweb_run "p=.git;a=history;f=deleted_file"'
500+
test_debug 'cat gitweb.log'
501+
486502
# ----------------------------------------------------------------------
487503
# feed generation
488504

0 commit comments

Comments
 (0)