Commit 9a9e8f3

Nick Faro committed on
tighten up so hackernews doesn't roast me
commit 9a9e8f364a684a2d47d6d639f4c70d560c685a19 parent 9a23bcc
27 changed files +1504−142
ModifiedLICENSE +661−21
@@ -1,21 +1,661 @@
1 MIT License 1 GNU AFFERO GENERAL PUBLIC LICENSE
2 2 Version 3, 19 November 2007
3 Copyright (c) 2026 Dumbforge contributors 3
4 4 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5 Permission is hereby granted, free of charge, to any person obtaining a copy 5 Everyone is permitted to copy and distribute verbatim copies
6 of this software and associated documentation files (the "Software"), to deal 6 of this license document, but changing it is not allowed.
7 in the Software without restriction, including without limitation the rights 7
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 Preamble
9 copies of the Software, and to permit persons to whom the Software is 9
10 furnished to do so, subject to the following conditions: 10 The GNU Affero General Public License is a free, copyleft license for
11 11 software and other kinds of works, specifically designed to ensure
12 The above copyright notice and this permission notice shall be included in all 12 cooperation with the community in the case of network server software.
13 copies or substantial portions of the Software. 13
14 14 The licenses for most software and other practical works are designed
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 to take away your freedom to share and change the works. By contrast,
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 our General Public Licenses are intended to guarantee your freedom to
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 share and change all versions of a program--to make sure it remains free
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 software for all its users.
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 When we speak of free software, we are referring to freedom, not
21 SOFTWARE. 21 price. Our General Public Licenses are designed to make sure that you
22 have the freedom to distribute copies of free software (and charge for
23 them if you wish), that you receive source code or can get it if you
24 want it, that you can change the software or use pieces of it in new
25 free programs, and that you know you can do these things.
26
27 Developers that use our General Public Licenses protect your rights
28 with two steps: (1) assert copyright on the software, and (2) offer
29 you this License which gives you legal permission to copy, distribute
30 and/or modify the software.
31
32 A secondary benefit of defending all users' freedom is that
33 improvements made in alternate versions of the program, if they
34 receive widespread use, become available for other developers to
35 incorporate. Many developers of free software are heartened and
36 encouraged by the resulting cooperation. However, in the case of
37 software used on network servers, this result may fail to come about.
38 The GNU General Public License permits making a modified version and
39 letting the public access it on a server without ever releasing its
40 source code to the public.
41
42 The GNU Affero General Public License is designed specifically to
43 ensure that, in such cases, the modified source code becomes available
44 to the community. It requires the operator of a network server to
45 provide the source code of the modified version running there to the
46 users of that server. Therefore, public use of a modified version, on
47 a publicly accessible server, gives the public access to the source
48 code of the modified version.
49
50 An older license, called the Affero General Public License and
51 published by Affero, was designed to accomplish similar goals. This is
52 a different license, not a version of the Affero GPL, but Affero has
53 released a new version of the Affero GPL which permits relicensing under
54 this license.
55
56 The precise terms and conditions for copying, distribution and
57 modification follow.
58
59 TERMS AND CONDITIONS
60
61 0. Definitions.
62
63 "This License" refers to version 3 of the GNU Affero General Public License.
64
65 "Copyright" also means copyright-like laws that apply to other kinds of
66 works, such as semiconductor masks.
67
68 "The Program" refers to any copyrightable work licensed under this
69 License. Each licensee is addressed as "you". "Licensees" and
70 "recipients" may be individuals or organizations.
71
72 To "modify" a work means to copy from or adapt all or part of the work
73 in a fashion requiring copyright permission, other than the making of an
74 exact copy. The resulting work is called a "modified version" of the
75 earlier work or a work "based on" the earlier work.
76
77 A "covered work" means either the unmodified Program or a work based
78 on the Program.
79
80 To "propagate" a work means to do anything with it that, without
81 permission, would make you directly or secondarily liable for
82 infringement under applicable copyright law, except executing it on a
83 computer or modifying a private copy. Propagation includes copying,
84 distribution (with or without modification), making available to the
85 public, and in some countries other activities as well.
86
87 To "convey" a work means any kind of propagation that enables other
88 parties to make or receive copies. Mere interaction with a user through
89 a computer network, with no transfer of a copy, is not conveying.
90
91 An interactive user interface displays "Appropriate Legal Notices"
92 to the extent that it includes a convenient and prominently visible
93 feature that (1) displays an appropriate copyright notice, and (2)
94 tells the user that there is no warranty for the work (except to the
95 extent that warranties are provided), that licensees may convey the
96 work under this License, and how to view a copy of this License. If
97 the interface presents a list of user commands or options, such as a
98 menu, a prominent item in the list meets this criterion.
99
100 1. Source Code.
101
102 The "source code" for a work means the preferred form of the work
103 for making modifications to it. "Object code" means any non-source
104 form of a work.
105
106 A "Standard Interface" means an interface that either is an official
107 standard defined by a recognized standards body, or, in the case of
108 interfaces specified for a particular programming language, one that
109 is widely used among developers working in that language.
110
111 The "System Libraries" of an executable work include anything, other
112 than the work as a whole, that (a) is included in the normal form of
113 packaging a Major Component, but which is not part of that Major
114 Component, and (b) serves only to enable use of the work with that
115 Major Component, or to implement a Standard Interface for which an
116 implementation is available to the public in source code form. A
117 "Major Component", in this context, means a major essential component
118 (kernel, window system, and so on) of the specific operating system
119 (if any) on which the executable work runs, or a compiler used to
120 produce the work, or an object code interpreter used to run it.
121
122 The "Corresponding Source" for a work in object code form means all
123 the source code needed to generate, install, and (for an executable
124 work) run the object code and to modify the work, including scripts to
125 control those activities. However, it does not include the work's
126 System Libraries, or general-purpose tools or generally available free
127 programs which are used unmodified in performing those activities but
128 which are not part of the work. For example, Corresponding Source
129 includes interface definition files associated with source files for
130 the work, and the source code for shared libraries and dynamically
131 linked subprograms that the work is specifically designed to require,
132 such as by intimate data communication or control flow between those
133 subprograms and other parts of the work.
134
135 The Corresponding Source need not include anything that users
136 can regenerate automatically from other parts of the Corresponding
137 Source.
138
139 The Corresponding Source for a work in source code form is that
140 same work.
141
142 2. Basic Permissions.
143
144 All rights granted under this License are granted for the term of
145 copyright on the Program, and are irrevocable provided the stated
146 conditions are met. This License explicitly affirms your unlimited
147 permission to run the unmodified Program. The output from running a
148 covered work is covered by this License only if the output, given its
149 content, constitutes a covered work. This License acknowledges your
150 rights of fair use or other equivalent, as provided by copyright law.
151
152 You may make, run and propagate covered works that you do not
153 convey, without conditions so long as your license otherwise remains
154 in force. You may convey covered works to others for the sole purpose
155 of having them make modifications exclusively for you, or provide you
156 with facilities for running those works, provided that you comply with
157 the terms of this License in conveying all material for which you do
158 not control copyright. Those thus making or running the covered works
159 for you must do so exclusively on your behalf, under your direction
160 and control, on terms that prohibit them from making any copies of
161 your copyrighted material outside their relationship with you.
162
163 Conveying under any other circumstances is permitted solely under
164 the conditions stated below. Sublicensing is not allowed; section 10
165 makes it unnecessary.
166
167 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168
169 No covered work shall be deemed part of an effective technological
170 measure under any applicable law fulfilling obligations under article
171 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 similar laws prohibiting or restricting circumvention of such
173 measures.
174
175 When you convey a covered work, you waive any legal power to forbid
176 circumvention of technological measures to the extent such circumvention
177 is effected by exercising rights under this License with respect to
178 the covered work, and you disclaim any intention to limit operation or
179 modification of the work as a means of enforcing, against the work's
180 users, your or third parties' legal rights to forbid circumvention of
181 technological measures.
182
183 4. Conveying Verbatim Copies.
184
185 You may convey verbatim copies of the Program's source code as you
186 receive it, in any medium, provided that you conspicuously and
187 appropriately publish on each copy an appropriate copyright notice;
188 keep intact all notices stating that this License and any
189 non-permissive terms added in accord with section 7 apply to the code;
190 keep intact all notices of the absence of any warranty; and give all
191 recipients a copy of this License along with the Program.
192
193 You may charge any price or no price for each copy that you convey,
194 and you may offer support or warranty protection for a fee.
195
196 5. Conveying Modified Source Versions.
197
198 You may convey a work based on the Program, or the modifications to
199 produce it from the Program, in the form of source code under the
200 terms of section 4, provided that you also meet all of these conditions:
201
202 a) The work must carry prominent notices stating that you modified
203 it, and giving a relevant date.
204
205 b) The work must carry prominent notices stating that it is
206 released under this License and any conditions added under section
207 7. This requirement modifies the requirement in section 4 to
208 "keep intact all notices".
209
210 c) You must license the entire work, as a whole, under this
211 License to anyone who comes into possession of a copy. This
212 License will therefore apply, along with any applicable section 7
213 additional terms, to the whole of the work, and all its parts,
214 regardless of how they are packaged. This License gives no
215 permission to license the work in any other way, but it does not
216 invalidate such permission if you have separately received it.
217
218 d) If the work has interactive user interfaces, each must display
219 Appropriate Legal Notices; however, if the Program has interactive
220 interfaces that do not display Appropriate Legal Notices, your
221 work need not make them do so.
222
223 A compilation of a covered work with other separate and independent
224 works, which are not by their nature extensions of the covered work,
225 and which are not combined with it such as to form a larger program,
226 in or on a volume of a storage or distribution medium, is called an
227 "aggregate" if the compilation and its resulting copyright are not
228 used to limit the access or legal rights of the compilation's users
229 beyond what the individual works permit. Inclusion of a covered work
230 in an aggregate does not cause this License to apply to the other
231 parts of the aggregate.
232
233 6. Conveying Non-Source Forms.
234
235 You may convey a covered work in object code form under the terms
236 of sections 4 and 5, provided that you also convey the
237 machine-readable Corresponding Source under the terms of this License,
238 in one of these ways:
239
240 a) Convey the object code in, or embodied in, a physical product
241 (including a physical distribution medium), accompanied by the
242 Corresponding Source fixed on a durable physical medium
243 customarily used for software interchange.
244
245 b) Convey the object code in, or embodied in, a physical product
246 (including a physical distribution medium), accompanied by a
247 written offer, valid for at least three years and valid for as
248 long as you offer spare parts or customer support for that product
249 model, to give anyone who possesses the object code either (1) a
250 copy of the Corresponding Source for all the software in the
251 product that is covered by this License, on a durable physical
252 medium customarily used for software interchange, for a price no
253 more than your reasonable cost of physically performing this
254 conveying of source, or (2) access to copy the
255 Corresponding Source from a network server at no charge.
256
257 c) Convey individual copies of the object code with a copy of the
258 written offer to provide the Corresponding Source. This
259 alternative is allowed only occasionally and noncommercially, and
260 only if you received the object code with such an offer, in accord
261 with subsection 6b.
262
263 d) Convey the object code by offering access from a designated
264 place (gratis or for a charge), and offer equivalent access to the
265 Corresponding Source in the same way through the same place at no
266 further charge. You need not require recipients to copy the
267 Corresponding Source along with the object code. If the place to
268 copy the object code is a network server, the Corresponding Source
269 may be on a different server (operated by you or a third party)
270 that supports equivalent copying facilities, provided you maintain
271 clear directions next to the object code saying where to find the
272 Corresponding Source. Regardless of what server hosts the
273 Corresponding Source, you remain obligated to ensure that it is
274 available for as long as needed to satisfy these requirements.
275
276 e) Convey the object code using peer-to-peer transmission, provided
277 you inform other peers where the object code and Corresponding
278 Source of the work are being offered to the general public at no
279 charge under subsection 6d.
280
281 A separable portion of the object code, whose source code is excluded
282 from the Corresponding Source as a System Library, need not be
283 included in conveying the object code work.
284
285 A "User Product" is either (1) a "consumer product", which means any
286 tangible personal property which is normally used for personal, family,
287 or household purposes, or (2) anything designed or sold for incorporation
288 into a dwelling. In determining whether a product is a consumer product,
289 doubtful cases shall be resolved in favor of coverage. For a particular
290 product received by a particular user, "normally used" refers to a
291 typical or common use of that class of product, regardless of the status
292 of the particular user or of the way in which the particular user
293 actually uses, or expects or is expected to use, the product. A product
294 is a consumer product regardless of whether the product has substantial
295 commercial, industrial or non-consumer uses, unless such uses represent
296 the only significant mode of use of the product.
297
298 "Installation Information" for a User Product means any methods,
299 procedures, authorization keys, or other information required to install
300 and execute modified versions of a covered work in that User Product from
301 a modified version of its Corresponding Source. The information must
302 suffice to ensure that the continued functioning of the modified object
303 code is in no case prevented or interfered with solely because
304 modification has been made.
305
306 If you convey an object code work under this section in, or with, or
307 specifically for use in, a User Product, and the conveying occurs as
308 part of a transaction in which the right of possession and use of the
309 User Product is transferred to the recipient in perpetuity or for a
310 fixed term (regardless of how the transaction is characterized), the
311 Corresponding Source conveyed under this section must be accompanied
312 by the Installation Information. But this requirement does not apply
313 if neither you nor any third party retains the ability to install
314 modified object code on the User Product (for example, the work has
315 been installed in ROM).
316
317 The requirement to provide Installation Information does not include a
318 requirement to continue to provide support service, warranty, or updates
319 for a work that has been modified or installed by the recipient, or for
320 the User Product in which it has been modified or installed. Access to a
321 network may be denied when the modification itself materially and
322 adversely affects the operation of the network or violates the rules and
323 protocols for communication across the network.
324
325 Corresponding Source conveyed, and Installation Information provided,
326 in accord with this section must be in a format that is publicly
327 documented (and with an implementation available to the public in
328 source code form), and must require no special password or key for
329 unpacking, reading or copying.
330
331 7. Additional Terms.
332
333 "Additional permissions" are terms that supplement the terms of this
334 License by making exceptions from one or more of its conditions.
335 Additional permissions that are applicable to the entire Program shall
336 be treated as though they were included in this License, to the extent
337 that they are valid under applicable law. If additional permissions
338 apply only to part of the Program, that part may be used separately
339 under those permissions, but the entire Program remains governed by
340 this License without regard to the additional permissions.
341
342 When you convey a copy of a covered work, you may at your option
343 remove any additional permissions from that copy, or from any part of
344 it. (Additional permissions may be written to require their own
345 removal in certain cases when you modify the work.) You may place
346 additional permissions on material, added by you to a covered work,
347 for which you have or can give appropriate copyright permission.
348
349 Notwithstanding any other provision of this License, for material you
350 add to a covered work, you may (if authorized by the copyright holders of
351 that material) supplement the terms of this License with terms:
352
353 a) Disclaiming warranty or limiting liability differently from the
354 terms of sections 15 and 16 of this License; or
355
356 b) Requiring preservation of specified reasonable legal notices or
357 author attributions in that material or in the Appropriate Legal
358 Notices displayed by works containing it; or
359
360 c) Prohibiting misrepresentation of the origin of that material, or
361 requiring that modified versions of such material be marked in
362 reasonable ways as different from the original version; or
363
364 d) Limiting the use for publicity purposes of names of licensors or
365 authors of the material; or
366
367 e) Declining to grant rights under trademark law for use of some
368 trade names, trademarks, or service marks; or
369
370 f) Requiring indemnification of licensors and authors of that
371 material by anyone who conveys the material (or modified versions of
372 it) with contractual assumptions of liability to the recipient, for
373 any liability that these contractual assumptions directly impose on
374 those licensors and authors.
375
376 All other non-permissive additional terms are considered "further
377 restrictions" within the meaning of section 10. If the Program as you
378 received it, or any part of it, contains a notice stating that it is
379 governed by this License along with a term that is a further
380 restriction, you may remove that term. If a license document contains
381 a further restriction but permits relicensing or conveying under this
382 License, you may add to a covered work material governed by the terms
383 of that license document, provided that the further restriction does
384 not survive such relicensing or conveying.
385
386 If you add terms to a covered work in accord with this section, you
387 must place, in the relevant source files, a statement of the
388 additional terms that apply to those files, or a notice indicating
389 where to find the applicable terms.
390
391 Additional terms, permissive or non-permissive, may be stated in the
392 form of a separately written license, or stated as exceptions;
393 the above requirements apply either way.
394
395 8. Termination.
396
397 You may not propagate or modify a covered work except as expressly
398 provided under this License. Any attempt otherwise to propagate or
399 modify it is void, and will automatically terminate your rights under
400 this License (including any patent licenses granted under the third
401 paragraph of section 11).
402
403 However, if you cease all violation of this License, then your
404 license from a particular copyright holder is reinstated (a)
405 provisionally, unless and until the copyright holder explicitly and
406 finally terminates your license, and (b) permanently, if the copyright
407 holder fails to notify you of the violation by some reasonable means
408 prior to 60 days after the cessation.
409
410 Moreover, your license from a particular copyright holder is
411 reinstated permanently if the copyright holder notifies you of the
412 violation by some reasonable means, this is the first time you have
413 received notice of violation of this License (for any work) from that
414 copyright holder, and you cure the violation prior to 30 days after
415 your receipt of the notice.
416
417 Termination of your rights under this section does not terminate the
418 licenses of parties who have received copies or rights from you under
419 this License. If your rights have been terminated and not permanently
420 reinstated, you do not qualify to receive new licenses for the same
421 material under section 10.
422
423 9. Acceptance Not Required for Having Copies.
424
425 You are not required to accept this License in order to receive or
426 run a copy of the Program. Ancillary propagation of a covered work
427 occurring solely as a consequence of using peer-to-peer transmission
428 to receive a copy likewise does not require acceptance. However,
429 nothing other than this License grants you permission to propagate or
430 modify any covered work. These actions infringe copyright if you do
431 not accept this License. Therefore, by modifying or propagating a
432 covered work, you indicate your acceptance of this License to do so.
433
434 10. Automatic Licensing of Downstream Recipients.
435
436 Each time you convey a covered work, the recipient automatically
437 receives a license from the original licensors, to run, modify and
438 propagate that work, subject to this License. You are not responsible
439 for enforcing compliance by third parties with this License.
440
441 An "entity transaction" is a transaction transferring control of an
442 organization, or substantially all assets of one, or subdividing an
443 organization, or merging organizations. If propagation of a covered
444 work results from an entity transaction, each party to that
445 transaction who receives a copy of the work also receives whatever
446 licenses to the work the party's predecessor in interest had or could
447 give under the previous paragraph, plus a right to possession of the
448 Corresponding Source of the work from the predecessor in interest, if
449 the predecessor has it or can get it with reasonable efforts.
450
451 You may not impose any further restrictions on the exercise of the
452 rights granted or affirmed under this License. For example, you may
453 not impose a license fee, royalty, or other charge for exercise of
454 rights granted under this License, and you may not initiate litigation
455 (including a cross-claim or counterclaim in a lawsuit) alleging that
456 any patent claim is infringed by making, using, selling, offering for
457 sale, or importing the Program or any portion of it.
458
459 11. Patents.
460
461 A "contributor" is a copyright holder who authorizes use under this
462 License of the Program or a work on which the Program is based. The
463 work thus licensed is called the contributor's "contributor version".
464
465 A contributor's "essential patent claims" are all patent claims
466 owned or controlled by the contributor, whether already acquired or
467 hereafter acquired, that would be infringed by some manner, permitted
468 by this License, of making, using, or selling its contributor version,
469 but do not include claims that would be infringed only as a
470 consequence of further modification of the contributor version. For
471 purposes of this definition, "control" includes the right to grant
472 patent sublicenses in a manner consistent with the requirements of
473 this License.
474
475 Each contributor grants you a non-exclusive, worldwide, royalty-free
476 patent license under the contributor's essential patent claims, to
477 make, use, sell, offer for sale, import and otherwise run, modify and
478 propagate the contents of its contributor version.
479
480 In the following three paragraphs, a "patent license" is any express
481 agreement or commitment, however denominated, not to enforce a patent
482 (such as an express permission to practice a patent or covenant not to
483 sue for patent infringement). To "grant" such a patent license to a
484 party means to make such an agreement or commitment not to enforce a
485 patent against the party.
486
487 If you convey a covered work, knowingly relying on a patent license,
488 and the Corresponding Source of the work is not available for anyone
489 to copy, free of charge and under the terms of this License, through a
490 publicly available network server or other readily accessible means,
491 then you must either (1) cause the Corresponding Source to be so
492 available, or (2) arrange to deprive yourself of the benefit of the
493 patent license for this particular work, or (3) arrange, in a manner
494 consistent with the requirements of this License, to extend the patent
495 license to downstream recipients. "Knowingly relying" means you have
496 actual knowledge that, but for the patent license, your conveying the
497 covered work in a country, or your recipient's use of the covered work
498 in a country, would infringe one or more identifiable patents in that
499 country that you have reason to believe are valid.
500
501 If, pursuant to or in connection with a single transaction or
502 arrangement, you convey, or propagate by procuring conveyance of, a
503 covered work, and grant a patent license to some of the parties
504 receiving the covered work authorizing them to use, propagate, modify
505 or convey a specific copy of the covered work, then the patent license
506 you grant is automatically extended to all recipients of the covered
507 work and works based on it.
508
509 A patent license is "discriminatory" if it does not include within
510 the scope of its coverage, prohibits the exercise of, or is
511 conditioned on the non-exercise of one or more of the rights that are
512 specifically granted under this License. You may not convey a covered
513 work if you are a party to an arrangement with a third party that is
514 in the business of distributing software, under which you make payment
515 to the third party based on the extent of your activity of conveying
516 the work, and under which the third party grants, to any of the
517 parties who would receive the covered work from you, a discriminatory
518 patent license (a) in connection with copies of the covered work
519 conveyed by you (or copies made from those copies), or (b) primarily
520 for and in connection with specific products or compilations that
521 contain the covered work, unless you entered into that arrangement,
522 or that patent license was granted, prior to 28 March 2007.
523
524 Nothing in this License shall be construed as excluding or limiting
525 any implied license or other defenses to infringement that may
526 otherwise be available to you under applicable patent law.
527
528 12. No Surrender of Others' Freedom.
529
530 If conditions are imposed on you (whether by court order, agreement or
531 otherwise) that contradict the conditions of this License, they do not
532 excuse you from the conditions of this License. If you cannot convey a
533 covered work so as to satisfy simultaneously your obligations under this
534 License and any other pertinent obligations, then as a consequence you may
535 not convey it at all. For example, if you agree to terms that obligate you
536 to collect a royalty for further conveying from those to whom you convey
537 the Program, the only way you could satisfy both those terms and this
538 License would be to refrain entirely from conveying the Program.
539
540 13. Remote Network Interaction; Use with the GNU General Public License.
541
542 Notwithstanding any other provision of this License, if you modify the
543 Program, your modified version must prominently offer all users
544 interacting with it remotely through a computer network (if your version
545 supports such interaction) an opportunity to receive the Corresponding
546 Source of your version by providing access to the Corresponding Source
547 from a network server at no charge, through some standard or customary
548 means of facilitating copying of software. This Corresponding Source
549 shall include the Corresponding Source for any work covered by version 3
550 of the GNU General Public License that is incorporated pursuant to the
551 following paragraph.
552
553 Notwithstanding any other provision of this License, you have
554 permission to link or combine any covered work with a work licensed
555 under version 3 of the GNU General Public License into a single
556 combined work, and to convey the resulting work. The terms of this
557 License will continue to apply to the part which is the covered work,
558 but the work with which it is combined will remain governed by version
559 3 of the GNU General Public License.
560
561 14. Revised Versions of this License.
562
563 The Free Software Foundation may publish revised and/or new versions of
564 the GNU Affero General Public License from time to time. Such new versions
565 will be similar in spirit to the present version, but may differ in detail to
566 address new problems or concerns.
567
568 Each version is given a distinguishing version number. If the
569 Program specifies that a certain numbered version of the GNU Affero General
570 Public License "or any later version" applies to it, you have the
571 option of following the terms and conditions either of that numbered
572 version or of any later version published by the Free Software
573 Foundation. If the Program does not specify a version number of the
574 GNU Affero General Public License, you may choose any version ever published
575 by the Free Software Foundation.
576
577 If the Program specifies that a proxy can decide which future
578 versions of the GNU Affero General Public License can be used, that proxy's
579 public statement of acceptance of a version permanently authorizes you
580 to choose that version for the Program.
581
582 Later license versions may give you additional or different
583 permissions. However, no additional obligations are imposed on any
584 author or copyright holder as a result of your choosing to follow a
585 later version.
586
587 15. Disclaimer of Warranty.
588
589 THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597
598 16. Limitation of Liability.
599
600 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 SUCH DAMAGES.
609
610 17. Interpretation of Sections 15 and 16.
611
612 If the disclaimer of warranty and limitation of liability provided
613 above cannot be given local legal effect according to their terms,
614 reviewing courts shall apply local law that most closely approximates
615 an absolute waiver of all civil liability in connection with the
616 Program, unless a warranty or assumption of liability accompanies a
617 copy of the Program in return for a fee.
618
619 END OF TERMS AND CONDITIONS
620
621 How to Apply These Terms to Your New Programs
622
623 If you develop a new program, and you want it to be of the greatest
624 possible use to the public, the best way to achieve this is to make it
625 free software which everyone can redistribute and change under these terms.
626
627 To do so, attach the following notices to the program. It is safest
628 to attach them to the start of each source file to most effectively
629 state the exclusion of warranty; and each file should have at least
630 the "copyright" line and a pointer to where the full notice is found.
631
632 <one line to give the program's name and a brief idea of what it does.>
633 Copyright (C) <year> <name of author>
634
635 This program is free software: you can redistribute it and/or modify
636 it under the terms of the GNU Affero General Public License as published by
637 the Free Software Foundation, either version 3 of the License, or
638 (at your option) any later version.
639
640 This program is distributed in the hope that it will be useful,
641 but WITHOUT ANY WARRANTY; without even the implied warranty of
642 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 GNU Affero General Public License for more details.
644
645 You should have received a copy of the GNU Affero General Public License
646 along with this program. If not, see <https://www.gnu.org/licenses/>.
647
648 Also add information on how to contact you by electronic and paper mail.
649
650 If your software can interact with users remotely through a computer
651 network, you should also make sure that it provides a way for users to
652 get its source. For example, if your program is a web application, its
653 interface could display a "Source" link that leads users to an archive
654 of the code. There are many ways you could offer source, and different
655 solutions will be better for different programs; see section 13 for the
656 specific requirements.
657
658 You should also get your employer (if you work as a programmer) or school,
659 if any, to sign a "copyright disclaimer" for the program, if necessary.
660 For more information on this, and how to apply and follow the GNU AGPL, see
661 <https://www.gnu.org/licenses/>.
ModifiedREADME.md +9−1
@@ -6,7 +6,7 @@ Well, everyone's [been talking about GitHub alternatives](https://mitchellh.com/
6 6
7 It occurred to me that you don't actually need to run a forge or git daemon at all, since Git supports cloning via the so-called ["dumb" HTTP protocol](https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols). You could theoretically just throw your git repo into an s3 bucket, and it would be clone-able, no daemon or VPS required. So that's cool, and even more decentralized; but the problem with self-hosting git like that, is that then you don't have the nice landing page, file browser, commit log, etc etc. It's small, but it makes a big difference to have a GitHubby UI for each project. [SourceHut](https://sourcehut.org/) and [Savannah](https://savannah.gnu.org/) struggle with this I think, since they're pretty alien to normies. 7 It occurred to me that you don't actually need to run a forge or git daemon at all, since Git supports cloning via the so-called ["dumb" HTTP protocol](https://git-scm.com/book/en/v2/Git-Internals-Transfer-Protocols). You could theoretically just throw your git repo into an s3 bucket, and it would be clone-able, no daemon or VPS required. So that's cool, and even more decentralized; but the problem with self-hosting git like that, is that then you don't have the nice landing page, file browser, commit log, etc etc. It's small, but it makes a big difference to have a GitHubby UI for each project. [SourceHut](https://sourcehut.org/) and [Savannah](https://savannah.gnu.org/) struggle with this I think, since they're pretty alien to normies.
8 8
9 So I slopped `dumbforge` together as a proof of concept; it's a static-site-generator-like-thing that functions as a git remote helper which pushes directly to an s3 bucket, and generates a GitHub-like UI. So you get some really nice advantages: 9 So I slopped `dumbforge` together as a proof of concept; it's a git remote helper that also functions as a static-site-generator-like-thing, which pushes directly to an s3 bucket, and generates a GitHub-like UI. So you get some really nice advantages:
10 10
11 1. It's super fast to browse, since it's just static HTML. GitLab and GitHub itself are really slow clunky beasts. 11 1. It's super fast to browse, since it's just static HTML. GitLab and GitHub itself are really slow clunky beasts.
12 2. You don't need to administer a git daemon or forge server. 12 2. You don't need to administer a git daemon or forge server.
@@ -15,6 +15,8 @@ So I slopped `dumbforge` together as a proof of concept; it's a static-site-gene
15 15
16 I'll grant that the implementation could most certainly use some improvement but this is mostly just to show off the idea. I hope it piques your curiosity. 🤔 16 I'll grant that the implementation could most certainly use some improvement but this is mostly just to show off the idea. I hope it piques your curiosity. 🤔
17 17
18 If you want to see one of my actual repos presented by `dumbforge`, [check here.](https://dumbforge.dev/hUGETracker.git)
19
18 **the following text is LLM generated** 20 **the following text is LLM generated**
19 21
20 ## Install 22 ## Install
@@ -164,6 +166,12 @@ If Git reports that `remote-dumbforge` is not a Git command, the npm global bin
164 directory is not on your `PATH`. `command -v git-remote-dumbforge` should print 166 directory is not on your `PATH`. `command -v git-remote-dumbforge` should print
165 the installed helper's path before you push. 167 the installed helper's path before you push.
166 168
169 ## License
170
171 dumbforge is licensed under the GNU Affero General Public License v3.0 only.
172 See [LICENSE](LICENSE). Third-party notices and license texts are included in
173 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
174
167 ## Development 175 ## Development
168 176
169 ```sh 177 ```sh
AddedTHIRD_PARTY_LICENSES/Apache-2.0.txt +202−0
@@ -0,0 +1,202 @@
1
2 Apache License
3 Version 2.0, January 2004
4 http://www.apache.org/licenses/
5
6 TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
8 1. Definitions.
9
10 "License" shall mean the terms and conditions for use, reproduction,
11 and distribution as defined by Sections 1 through 9 of this document.
12
13 "Licensor" shall mean the copyright owner or entity authorized by
14 the copyright owner that is granting the License.
15
16 "Legal Entity" shall mean the union of the acting entity and all
17 other entities that control, are controlled by, or are under common
18 control with that entity. For the purposes of this definition,
19 "control" means (i) the power, direct or indirect, to cause the
20 direction or management of such entity, whether by contract or
21 otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 outstanding shares, or (iii) beneficial ownership of such entity.
23
24 "You" (or "Your") shall mean an individual or Legal Entity
25 exercising permissions granted by this License.
26
27 "Source" form shall mean the preferred form for making modifications,
28 including but not limited to software source code, documentation
29 source, and configuration files.
30
31 "Object" form shall mean any form resulting from mechanical
32 transformation or translation of a Source form, including but
33 not limited to compiled object code, generated documentation,
34 and conversions to other media types.
35
36 "Work" shall mean the work of authorship, whether in Source or
37 Object form, made available under the License, as indicated by a
38 copyright notice that is included in or attached to the work
39 (an example is provided in the Appendix below).
40
41 "Derivative Works" shall mean any work, whether in Source or Object
42 form, that is based on (or derived from) the Work and for which the
43 editorial revisions, annotations, elaborations, or other modifications
44 represent, as a whole, an original work of authorship. For the purposes
45 of this License, Derivative Works shall not include works that remain
46 separable from, or merely link (or bind by name) to the interfaces of,
47 the Work and Derivative Works thereof.
48
49 "Contribution" shall mean any work of authorship, including
50 the original version of the Work and any modifications or additions
51 to that Work or Derivative Works thereof, that is intentionally
52 submitted to Licensor for inclusion in the Work by the copyright owner
53 or by an individual or Legal Entity authorized to submit on behalf of
54 the copyright owner. For the purposes of this definition, "submitted"
55 means any form of electronic, verbal, or written communication sent
56 to the Licensor or its representatives, including but not limited to
57 communication on electronic mailing lists, source code control systems,
58 and issue tracking systems that are managed by, or on behalf of, the
59 Licensor for the purpose of discussing and improving the Work, but
60 excluding communication that is conspicuously marked or otherwise
61 designated in writing by the copyright owner as "Not a Contribution."
62
63 "Contributor" shall mean Licensor and any individual or Legal Entity
64 on behalf of whom a Contribution has been received by Licensor and
65 subsequently incorporated within the Work.
66
67 2. Grant of Copyright License. Subject to the terms and conditions of
68 this License, each Contributor hereby grants to You a perpetual,
69 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 copyright license to reproduce, prepare Derivative Works of,
71 publicly display, publicly perform, sublicense, and distribute the
72 Work and such Derivative Works in Source or Object form.
73
74 3. Grant of Patent License. Subject to the terms and conditions of
75 this License, each Contributor hereby grants to You a perpetual,
76 worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 (except as stated in this section) patent license to make, have made,
78 use, offer to sell, sell, import, and otherwise transfer the Work,
79 where such license applies only to those patent claims licensable
80 by such Contributor that are necessarily infringed by their
81 Contribution(s) alone or by combination of their Contribution(s)
82 with the Work to which such Contribution(s) was submitted. If You
83 institute patent litigation against any entity (including a
84 cross-claim or counterclaim in a lawsuit) alleging that the Work
85 or a Contribution incorporated within the Work constitutes direct
86 or contributory patent infringement, then any patent licenses
87 granted to You under this License for that Work shall terminate
88 as of the date such litigation is filed.
89
90 4. Redistribution. You may reproduce and distribute copies of the
91 Work or Derivative Works thereof in any medium, with or without
92 modifications, and in Source or Object form, provided that You
93 meet the following conditions:
94
95 (a) You must give any other recipients of the Work or
96 Derivative Works a copy of this License; and
97
98 (b) You must cause any modified files to carry prominent notices
99 stating that You changed the files; and
100
101 (c) You must retain, in the Source form of any Derivative Works
102 that You distribute, all copyright, patent, trademark, and
103 attribution notices from the Source form of the Work,
104 excluding those notices that do not pertain to any part of
105 the Derivative Works; and
106
107 (d) If the Work includes a "NOTICE" text file as part of its
108 distribution, then any Derivative Works that You distribute must
109 include a readable copy of the attribution notices contained
110 within such NOTICE file, excluding those notices that do not
111 pertain to any part of the Derivative Works, in at least one
112 of the following places: within a NOTICE text file distributed
113 as part of the Derivative Works; within the Source form or
114 documentation, if provided along with the Derivative Works; or,
115 within a display generated by the Derivative Works, if and
116 wherever such third-party notices normally appear. The contents
117 of the NOTICE file are for informational purposes only and
118 do not modify the License. You may add Your own attribution
119 notices within Derivative Works that You distribute, alongside
120 or as an addendum to the NOTICE text from the Work, provided
121 that such additional attribution notices cannot be construed
122 as modifying the License.
123
124 You may add Your own copyright statement to Your modifications and
125 may provide additional or different license terms and conditions
126 for use, reproduction, or distribution of Your modifications, or
127 for any such Derivative Works as a whole, provided Your use,
128 reproduction, and distribution of the Work otherwise complies with
129 the conditions stated in this License.
130
131 5. Submission of Contributions. Unless You explicitly state otherwise,
132 any Contribution intentionally submitted for inclusion in the Work
133 by You to the Licensor shall be under the terms and conditions of
134 this License, without any additional terms or conditions.
135 Notwithstanding the above, nothing herein shall supersede or modify
136 the terms of any separate license agreement you may have executed
137 with Licensor regarding such Contributions.
138
139 6. Trademarks. This License does not grant permission to use the trade
140 names, trademarks, service marks, or product names of the Licensor,
141 except as required for reasonable and customary use in describing the
142 origin of the Work and reproducing the content of the NOTICE file.
143
144 7. Disclaimer of Warranty. Unless required by applicable law or
145 agreed to in writing, Licensor provides the Work (and each
146 Contributor provides its Contributions) on an "AS IS" BASIS,
147 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 implied, including, without limitation, any warranties or conditions
149 of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 PARTICULAR PURPOSE. You are solely responsible for determining the
151 appropriateness of using or redistributing the Work and assume any
152 risks associated with Your exercise of permissions under this License.
153
154 8. Limitation of Liability. In no event and under no legal theory,
155 whether in tort (including negligence), contract, or otherwise,
156 unless required by applicable law (such as deliberate and grossly
157 negligent acts) or agreed to in writing, shall any Contributor be
158 liable to You for damages, including any direct, indirect, special,
159 incidental, or consequential damages of any character arising as a
160 result of this License or out of the use or inability to use the
161 Work (including but not limited to damages for loss of goodwill,
162 work stoppage, computer failure or malfunction, or any and all
163 other commercial damages or losses), even if such Contributor
164 has been advised of the possibility of such damages.
165
166 9. Accepting Warranty or Additional Liability. While redistributing
167 the Work or Derivative Works thereof, You may choose to offer,
168 and charge a fee for, acceptance of support, warranty, indemnity,
169 or other liability obligations and/or rights consistent with this
170 License. However, in accepting such obligations, You may act only
171 on Your own behalf and on Your sole responsibility, not on behalf
172 of any other Contributor, and only if You agree to indemnify,
173 defend, and hold each Contributor harmless for any liability
174 incurred by, or claims asserted against, such Contributor by reason
175 of your accepting any such warranty or additional liability.
176
177 END OF TERMS AND CONDITIONS
178
179 APPENDIX: How to apply the Apache License to your work.
180
181 To apply the Apache License to your work, attach the following
182 boilerplate notice, with the fields enclosed by brackets "[]"
183 replaced with your own identifying information. (Don't include
184 the brackets!) The text should be enclosed in the appropriate
185 comment syntax for the file format. We also recommend that a
186 file or class name and description of purpose be included on the
187 same "printed page" as the copyright notice for easier
188 identification within third-party archives.
189
190 Copyright [yyyy] [name of copyright owner]
191
192 Licensed under the Apache License, Version 2.0 (the "License");
193 you may not use this file except in compliance with the License.
194 You may obtain a copy of the License at
195
196 http://www.apache.org/licenses/LICENSE-2.0
197
198 Unless required by applicable law or agreed to in writing, software
199 distributed under the License is distributed on an "AS IS" BASIS,
200 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 See the License for the specific language governing permissions and
202 limitations under the License.
AddedTHIRD_PARTY_LICENSES/Go-BSD-3-Clause.txt +27−0
@@ -0,0 +1,27 @@
1 Copyright 2009 The Go Authors.
2
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions are
5 met:
6
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Google LLC nor the names of its
14 contributors may be used to endorse or promote products derived from
15 this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AddedTHIRD_PARTY_LICENSES/MIT.txt +21−0
@@ -0,0 +1,21 @@
1 MIT License
2
3 Copyright (c) 2019 Yusuke Inuzuka
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 SOFTWARE.
ModifiedTHIRD_PARTY_NOTICES.md +31−20
@@ -1,28 +1,39 @@
1 # Third-party notices 1 # Third-party notices
2 2
3 ## Primer Octicons 3 dumbforge's native executable and generated repository browser include the
4 following third-party software. The complete license texts referenced below
5 are shipped in `THIRD_PARTY_LICENSES`.
4 6
5 Selected SVG paths from Primer Octicons 19.31.0 are embedded in Dumbforge's 7 ## Apache-2.0 components
6 generated repository browser.
7 8
8 Copyright (c) 2026 GitHub Inc. 9 - AWS SDK for Go v2 and its service/internal modules
10 - AWS Smithy for Go
11 - go-enry
9 12
10 MIT License 13 These components are licensed under the Apache License 2.0. See
14 `THIRD_PARTY_LICENSES/Apache-2.0.txt`.
11 15
12 Permission is hereby granted, free of charge, to any person obtaining a copy 16 AWS SDK for Go
13 of this software and associated documentation files (the "Software"), to deal 17 Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
14 in the Software without restriction, including without limitation the rights 18 Copyright 2014-2015 Stripe, Inc.
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18 19
19 The above copyright notice and this permission notice shall be included in all 20 AWS Smithy for Go
20 copies or substantial portions of the Software. 21 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
21 22
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 ## MIT components
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 - Chroma — Copyright (C) 2017 Alec Thomas
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 - regexp2 — Copyright (c) Doug Clark
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 - goldmark — Copyright (c) 2019 Yusuke Inuzuka
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 - Primer Octicons 19.31.0 — Copyright (c) 2026 GitHub Inc.
28 SOFTWARE. 29
30 These components are licensed under the MIT License. See
31 `THIRD_PARTY_LICENSES/MIT.txt`.
32
33 Selected SVG paths from Primer Octicons are embedded in the generated
34 repository browser.
35
36 ## Go
37
38 The native executables include portions of the Go standard library and
39 runtime. See `THIRD_PARTY_LICENSES/Go-BSD-3-Clause.txt`.
Modifiedcmd/dumbforge/main.go +6−2
@@ -6,6 +6,7 @@ import (
6 "fmt" 6 "fmt"
7 "os" 7 "os"
8 "os/exec" 8 "os/exec"
9 "os/signal"
9 "path" 10 "path"
10 "path/filepath" 11 "path/filepath"
11 "strings" 12 "strings"
@@ -21,7 +22,8 @@ import (
21 var version = "0.1.0-dev" 22 var version = "0.1.0-dev"
22 23
23 func main() { 24 func main() {
24 ctx := context.Background() 25 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
26 defer stop()
25 base := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe") 27 base := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
26 if base == "git-remote-dumbforge" { 28 if base == "git-remote-dumbforge" {
27 if len(os.Args) < 3 { 29 if len(os.Args) < 3 {
@@ -175,7 +177,7 @@ func remoteCommand(args []string) error {
175 if fetchURL == "" { 177 if fetchURL == "" {
176 return fmt.Errorf("public URL is required") 178 return fmt.Errorf("public URL is required")
177 } 179 }
178 if err := runGit("remote", "add", name, fetchURL); err != nil { 180 if err := runGit("remote", "add", "--", name, fetchURL); err != nil {
179 return err 181 return err
180 } 182 }
181 if err := runGit("config", "--add", "remote."+name+".pushurl", pushURL); err != nil { 183 if err := runGit("config", "--add", "remote."+name+".pushurl", pushURL); err != nil {
@@ -186,6 +188,7 @@ func remoteCommand(args []string) error {
186 } 188 }
187 189
188 func runGit(args ...string) error { 190 func runGit(args ...string) error {
191 // #nosec G204 G702 -- arguments are passed directly to Git without a shell.
189 cmd := exec.Command("git", args...) 192 cmd := exec.Command("git", args...)
190 cmd.Stdout = os.Stdout 193 cmd.Stdout = os.Stdout
191 cmd.Stderr = os.Stderr 194 cmd.Stderr = os.Stderr
@@ -196,6 +199,7 @@ func runGit(args ...string) error {
196 } 199 }
197 200
198 func gitOutput(args ...string) ([]byte, error) { 201 func gitOutput(args ...string) ([]byte, error) {
202 // #nosec G204 -- arguments are passed directly to Git without a shell.
199 cmd := exec.Command("git", args...) 203 cmd := exec.Command("git", args...)
200 var stderr strings.Builder 204 var stderr strings.Builder
201 cmd.Stderr = &stderr 205 cmd.Stderr = &stderr
Modifiedinternal/gitutil/git.go +4−1
@@ -7,6 +7,7 @@ import (
7 "encoding/binary" 7 "encoding/binary"
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "io"
10 "os" 11 "os"
11 "os/exec" 12 "os/exec"
12 "path/filepath" 13 "path/filepath"
@@ -22,6 +23,7 @@ func (g Git) command(ctx context.Context, args ...string) *exec.Cmd {
22 if g.Dir != "" { 23 if g.Dir != "" {
23 args = append([]string{"-C", g.Dir}, args...) 24 args = append([]string{"-C", g.Dir}, args...)
24 } 25 }
26 // #nosec G204 -- arguments are passed directly to Git without a shell.
25 return exec.CommandContext(ctx, "git", args...) 27 return exec.CommandContext(ctx, "git", args...)
26 } 28 }
27 29
@@ -156,13 +158,14 @@ func (g Git) PackObjects(ctx context.Context, wants, possibleHaves []string) (*P
156 } 158 }
157 159
158 func packObjectCount(filename string) (uint32, error) { 160 func packObjectCount(filename string) (uint32, error) {
161 // #nosec G304 -- filename is an internal path in our private temporary directory.
159 f, err := os.Open(filename) 162 f, err := os.Open(filename)
160 if err != nil { 163 if err != nil {
161 return 0, err 164 return 0, err
162 } 165 }
163 defer f.Close() 166 defer f.Close()
164 header := make([]byte, 12) 167 header := make([]byte, 12)
165 if _, err := f.Read(header); err != nil { 168 if _, err := io.ReadFull(f, header); err != nil {
166 return 0, fmt.Errorf("read pack header: %w", err) 169 return 0, fmt.Errorf("read pack header: %w", err)
167 } 170 }
168 if string(header[:4]) != "PACK" { 171 if string(header[:4]) != "PACK" {
Modifiedinternal/remoteurl/remoteurl.go +66−11
@@ -25,6 +25,14 @@ func Parse(raw string) (Spec, error) {
25 if u.Scheme != "dumbforge" { 25 if u.Scheme != "dumbforge" {
26 return Spec{}, fmt.Errorf("unsupported remote scheme %q", u.Scheme) 26 return Spec{}, fmt.Errorf("unsupported remote scheme %q", u.Scheme)
27 } 27 }
28 if u.Fragment != "" {
29 return Spec{}, fmt.Errorf("remote URL must not contain a fragment")
30 }
31 if u.User != nil {
32 if _, hasPassword := u.User.Password(); hasPassword {
33 return Spec{}, fmt.Errorf("credentials must not be embedded in the remote URL")
34 }
35 }
28 36
29 spec := Spec{ 37 spec := Spec{
30 Bucket: u.Hostname(), 38 Bucket: u.Hostname(),
@@ -35,21 +43,16 @@ func Parse(raw string) (Spec, error) {
35 if u.User != nil { 43 if u.User != nil {
36 spec.Profile = u.User.Username() 44 spec.Profile = u.User.Username()
37 } 45 }
38 if spec.Bucket == "" { 46 if err := validate(spec); err != nil {
39 return Spec{}, fmt.Errorf("remote URL is missing a bucket") 47 return Spec{}, err
40 }
41 if spec.Prefix == "" {
42 return Spec{}, fmt.Errorf("remote URL is missing a repository prefix")
43 }
44 if spec.Endpoint == "" {
45 return Spec{}, fmt.Errorf("remote URL is missing the S3 endpoint query parameter")
46 } 48 }
47 return spec, nil 49 return spec, nil
48 } 50 }
49 51
50 func Build(spec Spec) (string, error) { 52 func Build(spec Spec) (string, error) {
51 if spec.Bucket == "" || spec.Prefix == "" || spec.Endpoint == "" { 53 spec.Prefix = strings.Trim(spec.Prefix, "/")
52 return "", fmt.Errorf("bucket, prefix, and endpoint are required") 54 if err := validate(spec); err != nil {
55 return "", err
53 } 56 }
54 u := &url.URL{ 57 u := &url.URL{
55 Scheme: "dumbforge", 58 Scheme: "dumbforge",
@@ -72,5 +75,57 @@ func (s Spec) PublicRepoURL() string {
72 if s.PublicURL == "" { 75 if s.PublicURL == "" {
73 return "" 76 return ""
74 } 77 }
75 return strings.TrimRight(s.PublicURL, "/") + "/" + path.Clean(strings.Trim(s.Prefix, "/")) 78 base, err := url.Parse(s.PublicURL)
79 if err != nil {
80 return ""
81 }
82 base.Path = strings.TrimRight(base.Path, "/") + "/" + path.Clean(strings.Trim(s.Prefix, "/"))
83 base.RawPath = ""
84 return base.String()
85 }
86
87 func validate(spec Spec) error {
88 if spec.Bucket == "" {
89 return fmt.Errorf("bucket is required")
90 }
91 if strings.ContainsAny(spec.Bucket, "/\\\x00\r\n\t ") {
92 return fmt.Errorf("bucket contains invalid characters")
93 }
94 if spec.Prefix == "" {
95 return fmt.Errorf("repository prefix is required")
96 }
97 unsafeSegment := false
98 for _, segment := range strings.Split(spec.Prefix, "/") {
99 if segment == "." || segment == ".." {
100 unsafeSegment = true
101 break
102 }
103 }
104 if strings.ContainsAny(spec.Prefix, "\\\x00\r\n") || path.Clean(spec.Prefix) != spec.Prefix || unsafeSegment {
105 return fmt.Errorf("repository prefix must be a canonical relative object path")
106 }
107 if err := validateHTTPURL("S3 endpoint", spec.Endpoint, true); err != nil {
108 return err
109 }
110 if err := validateHTTPURL("public URL", spec.PublicURL, false); err != nil {
111 return err
112 }
113 return nil
114 }
115
116 func validateHTTPURL(label, value string, required bool) error {
117 if value == "" {
118 if required {
119 return fmt.Errorf("%s is required", label)
120 }
121 return nil
122 }
123 parsed, err := url.Parse(value)
124 if err != nil || (parsed.Scheme != "https" && parsed.Scheme != "http") || parsed.Host == "" {
125 return fmt.Errorf("%s must be an absolute HTTP or HTTPS URL", label)
126 }
127 if parsed.User != nil || parsed.RawQuery != "" || parsed.Fragment != "" {
128 return fmt.Errorf("%s must not contain credentials, a query, or a fragment", label)
129 }
130 return nil
76 } 131 }
Modifiedinternal/remoteurl/remoteurl_test.go +68−1
@@ -1,6 +1,9 @@
1 package remoteurl 1 package remoteurl
2 2
3 import "testing" 3 import (
4 "strings"
5 "testing"
6 )
4 7
5 func TestRoundTrip(t *testing.T) { 8 func TestRoundTrip(t *testing.T) {
6 want := Spec{ 9 want := Spec{
@@ -25,3 +28,67 @@ func TestRoundTrip(t *testing.T) {
25 t.Fatalf("unexpected public URL %q", got.PublicRepoURL()) 28 t.Fatalf("unexpected public URL %q", got.PublicRepoURL())
26 } 29 }
27 } 30 }
31
32 func TestPublicRepoURLEscapesObjectPath(t *testing.T) {
33 spec := Spec{
34 Bucket: "bucket",
35 Prefix: "projects/my repo.git",
36 Endpoint: "https://example.invalid",
37 PublicURL: "https://public.invalid/git",
38 }
39 raw, err := Build(spec)
40 if err != nil {
41 t.Fatal(err)
42 }
43 parsed, err := Parse(raw)
44 if err != nil {
45 t.Fatal(err)
46 }
47 if got := parsed.PublicRepoURL(); got != "https://public.invalid/git/projects/my%20repo.git" {
48 t.Fatalf("unexpected public URL %q", got)
49 }
50 }
51
52 func TestRejectsUnsafeLocations(t *testing.T) {
53 tests := []struct {
54 name string
55 spec Spec
56 want string
57 }{
58 {
59 name: "parent prefix",
60 spec: Spec{Bucket: "bucket", Prefix: "../other.git", Endpoint: "https://example.invalid"},
61 want: "canonical relative object path",
62 },
63 {
64 name: "duplicate separator",
65 spec: Spec{Bucket: "bucket", Prefix: "projects//repo.git", Endpoint: "https://example.invalid"},
66 want: "canonical relative object path",
67 },
68 {
69 name: "endpoint scheme",
70 spec: Spec{Bucket: "bucket", Prefix: "repo.git", Endpoint: "file:///tmp/bucket"},
71 want: "absolute HTTP or HTTPS URL",
72 },
73 {
74 name: "public credentials",
75 spec: Spec{Bucket: "bucket", Prefix: "repo.git", Endpoint: "https://example.invalid", PublicURL: "https://user:[email protected]"},
76 want: "must not contain credentials",
77 },
78 }
79 for _, test := range tests {
80 t.Run(test.name, func(t *testing.T) {
81 _, err := Build(test.spec)
82 if err == nil || !strings.Contains(err.Error(), test.want) {
83 t.Fatalf("Build() error = %v, want %q", err, test.want)
84 }
85 })
86 }
87 }
88
89 func TestParseRejectsEmbeddedSecret(t *testing.T) {
90 _, err := Parse("dumbforge://profile:secret@bucket/repo.git?endpoint=https%3A%2F%2Fexample.invalid")
91 if err == nil || !strings.Contains(err.Error(), "must not be embedded") {
92 t.Fatalf("Parse() error = %v", err)
93 }
94 }
Modifiedinternal/s3store/store.go +1−0
@@ -108,6 +108,7 @@ func (s *Store) PutRoot(ctx context.Context, data []byte, contentType, cacheCont
108 } 108 }
109 109
110 func (s *Store) PutFile(ctx context.Context, name, filename, contentType, cacheControl string) error { 110 func (s *Store) PutFile(ctx context.Context, name, filename, contentType, cacheControl string) error {
111 // #nosec G304 -- callers pass paths produced in our private pack directory.
111 f, err := os.Open(filename) 112 f, err := os.Open(filename)
112 if err != nil { 113 if err != nil {
113 return err 114 return err
Modifiedinternal/site/icons.go +1−0
@@ -30,5 +30,6 @@ func icon(name string) template.HTML {
30 if !ok { 30 if !ok {
31 return "" 31 return ""
32 } 32 }
33 // #nosec G203 -- names and SVG paths come only from the static map above.
33 return template.HTML(`<svg class="icon octicon-` + name + `" viewBox="0 0 16 16" aria-hidden="true">` + path + `</svg>`) 34 return template.HTML(`<svg class="icon octicon-` + name + `" viewBox="0 0 16 16" aria-hidden="true">` + path + `</svg>`)
34 } 35 }
Modifiedinternal/site/metadata.go +13−3
@@ -8,6 +8,7 @@ import (
8 "fmt" 8 "fmt"
9 "html/template" 9 "html/template"
10 "net/url" 10 "net/url"
11 "path"
11 "regexp" 12 "regexp"
12 "sort" 13 "sort"
13 "strings" 14 "strings"
@@ -75,7 +76,7 @@ func (g *Generator) branchSummary(ctx context.Context, branch, oid string) (bran
75 return branchSummary{ 76 return branchSummary{
76 Latest: commits[0], 77 Latest: commits[0],
77 Count: len(commits), 78 Count: len(commits),
78 CommitsURL: routeURL(g.BaseURL, "commits/"+branch), 79 CommitsURL: routeURL(g.BaseURL, path.Join("commits", branchRouteSegment(branch))),
79 Groups: groupCommits(commits), 80 Groups: groupCommits(commits),
80 Repository: repository, 81 Repository: repository,
81 }, nil 82 }, nil
@@ -237,7 +238,15 @@ func normalizeRepositoryURL(value string) string {
237 if strings.HasPrefix(value, "ssh://git@") { 238 if strings.HasPrefix(value, "ssh://git@") {
238 value = "https://" + strings.TrimPrefix(value, "ssh://git@") 239 value = "https://" + strings.TrimPrefix(value, "ssh://git@")
239 } 240 }
240 return strings.TrimSuffix(value, ".git") 241 parsed, err := url.Parse(value)
242 if err == nil {
243 switch strings.ToLower(parsed.Hostname()) {
244 case "github.com", "gitlab.com", "bitbucket.org", "codeberg.org", "gitea.com":
245 parsed.Path = strings.TrimSuffix(parsed.Path, ".git")
246 return parsed.String()
247 }
248 }
249 return value
241 } 250 }
242 251
243 func repositoryOwner(value string) string { 252 func repositoryOwner(value string) string {
@@ -400,7 +409,8 @@ func (g *Generator) languageStats(ctx context.Context, oid string) ([]LanguageSt
400 Name: language, 409 Name: language,
401 Bytes: size, 410 Bytes: size,
402 Percent: fmt.Sprintf("%.1f", percentage), 411 Percent: fmt.Sprintf("%.1f", percentage),
403 Style: template.CSS(fmt.Sprintf("--language-color:%s;--language-width:%.4f%%", color, percentage)), 412 // #nosec G203 -- color is from enry or a generated hex value; width is numeric.
413 Style: template.CSS(fmt.Sprintf("--language-color:%s;--language-width:%.4f%%", color, percentage)),
404 }) 414 })
405 } 415 }
406 sort.Slice(result, func(i, j int) bool { 416 sort.Slice(result, func(i, j int) bool {
Modifiedinternal/site/navigation.go +8−6
@@ -59,15 +59,17 @@ func (g *Generator) filesPage(ctx context.Context, branch, oid string) (Page, er
59 if err != nil { 59 if err != nil {
60 return Page{}, err 60 return Page{}, err
61 } 61 }
62 g.decorateSubmodules(ctx, oid, "", entries)
62 manifest := fileNavigation{} 63 manifest := fileNavigation{}
63 for _, entry := range entries { 64 for _, entry := range entries {
64 if entry.Type == "tree" { 65 if entry.Type == "tree" {
65 continue 66 continue
66 } 67 }
67 manifest.Files = append(manifest.Files, fileNavigationEntry{ 68 entryURL := routeURL(g.BaseURL, path.Join("blob", branchRouteSegment(branch), entry.Name))
68 Path: entry.Name, 69 if entry.SubmoduleURL != "" {
69 URL: routeURL(g.BaseURL, path.Join("blob", branch, entry.Name)), 70 entryURL = entry.SubmoduleURL
70 }) 71 }
72 manifest.Files = append(manifest.Files, fileNavigationEntry{Path: entry.Name, URL: entryURL})
71 } 73 }
72 sort.Slice(manifest.Files, func(i, j int) bool { 74 sort.Slice(manifest.Files, func(i, j int) bool {
73 return manifest.Files[i].Path < manifest.Files[j].Path 75 return manifest.Files[i].Path < manifest.Files[j].Path
@@ -77,7 +79,7 @@ func (g *Generator) filesPage(ctx context.Context, branch, oid string) (Page, er
77 return Page{}, err 79 return Page{}, err
78 } 80 }
79 return Page{ 81 return Page{
80 Route: path.Join(".dumbforge/files", branch+".json"), 82 Route: path.Join(".dumbforge/files", branchRouteSegment(branch)+".json"),
81 Body: body, 83 Body: body,
82 ContentType: "application/json; charset=utf-8", 84 ContentType: "application/json; charset=utf-8",
83 Cache: siteCache, 85 Cache: siteCache,
@@ -100,7 +102,7 @@ func (g *Generator) RepositoryNavigationBuild(deletedBranches []string) (Build,
100 Cache: siteCache, 102 Cache: siteCache,
101 }}} 103 }}}
102 for _, branch := range deletedBranches { 104 for _, branch := range deletedBranches {
103 build.Deletes = append(build.Deletes, path.Join(".dumbforge/files", branch+".json")) 105 build.Deletes = append(build.Deletes, path.Join(".dumbforge/files", branchRouteSegment(branch)+".json"))
104 } 106 }
105 return build, nil 107 return build, nil
106 } 108 }
Modifiedinternal/site/site.go +75−36
@@ -44,15 +44,17 @@ type Build struct {
44 } 44 }
45 45
46 type Generator struct { 46 type Generator struct {
47 Git gitutil.Git 47 Git gitutil.Git
48 BaseURL string 48 BaseURL string
49 RepoName string 49 RepoName string
50 Owner string 50 Owner string
51 CloneURL string 51 CloneURL string
52 Branches []string 52 Branches []string
53 DefaultBranch string 53 DefaultBranch string
54 Progress func(format string, args ...any) 54 Progress func(format string, args ...any)
55 templates *template.Template 55 templates *template.Template
56 submoduleMu sync.Mutex
57 submoduleCache map[string]map[string]string
56 } 58 }
57 59
58 type Commit struct { 60 type Commit struct {
@@ -76,6 +78,7 @@ type TreeEntry struct {
76 URL string 78 URL string
77 CommitMessage string 79 CommitMessage string
78 CommitURL string 80 CommitURL string
81 SubmoduleURL string
79 } 82 }
80 83
81 type Crumb struct { 84 type Crumb struct {
@@ -119,6 +122,9 @@ type pageData struct {
119 FileSize int64 122 FileSize int64
120 IsImage bool 123 IsImage bool
121 IsMarkdown bool 124 IsMarkdown bool
125 IsSubmodule bool
126 SubmoduleURL string
127 SubmoduleOID string
122 } 128 }
123 129
124 func New(git gitutil.Git, baseURL, repoName, owner string) (*Generator, error) { 130 func New(git gitutil.Git, baseURL, repoName, owner string) (*Generator, error) {
@@ -175,6 +181,7 @@ func (g *Generator) BuildBranch(ctx context.Context, branch, oldOID, newOID stri
175 if err != nil { 181 if err != nil {
176 return Build{}, err 182 return Build{}, err
177 } 183 }
184 g.decorateSubmodules(ctx, newOID, "", entries)
178 dirs := map[string]struct{}{"": {}} 185 dirs := map[string]struct{}{"": {}}
179 for _, entry := range entries { 186 for _, entry := range entries {
180 if entry.Type == "tree" { 187 if entry.Type == "tree" {
@@ -207,15 +214,15 @@ func (g *Generator) BuildBranch(ctx context.Context, branch, oldOID, newOID stri
207 for _, change := range changes { 214 for _, change := range changes {
208 if change.OldPath != "" { 215 if change.OldPath != "" {
209 result.Deletes = append(result.Deletes, 216 result.Deletes = append(result.Deletes,
210 path.Join("blob", branch, change.OldPath), 217 path.Join("blob", branchRouteSegment(branch), change.OldPath),
211 path.Join("raw", branch, change.OldPath), 218 path.Join("raw", branchRouteSegment(branch), change.OldPath),
212 ) 219 )
213 addAncestorDirs(dirs, change.OldPath) 220 addAncestorDirs(dirs, change.OldPath)
214 } 221 }
215 if strings.HasPrefix(change.Status, "D") { 222 if strings.HasPrefix(change.Status, "D") {
216 result.Deletes = append(result.Deletes, 223 result.Deletes = append(result.Deletes,
217 path.Join("blob", branch, change.Path), 224 path.Join("blob", branchRouteSegment(branch), change.Path),
218 path.Join("raw", branch, change.Path), 225 path.Join("raw", branchRouteSegment(branch), change.Path),
219 ) 226 )
220 addAncestorDirs(dirs, change.Path) 227 addAncestorDirs(dirs, change.Path)
221 continue 228 continue
@@ -224,7 +231,9 @@ func (g *Generator) BuildBranch(ctx context.Context, branch, oldOID, newOID stri
224 if err != nil { 231 if err != nil {
225 return Build{}, err 232 return Build{}, err
226 } 233 }
227 pages, err := g.blobPages(ctx, branch, newOID, entry, summary) 234 changedEntries := []TreeEntry{entry}
235 g.decorateSubmodules(ctx, newOID, "", changedEntries)
236 pages, err := g.blobPages(ctx, branch, newOID, changedEntries[0], summary)
228 if err != nil { 237 if err != nil {
229 return Build{}, err 238 return Build{}, err
230 } 239 }
@@ -240,7 +249,7 @@ func (g *Generator) BuildBranch(ctx context.Context, branch, oldOID, newOID stri
240 return Build{}, err 249 return Build{}, err
241 } 250 }
242 if !exists { 251 if !exists {
243 result.Deletes = append(result.Deletes, path.Join("tree", branch, dir)) 252 result.Deletes = append(result.Deletes, path.Join("tree", branchRouteSegment(branch), dir))
244 continue 253 continue
245 } 254 }
246 page, err := g.treePage(ctx, branch, newOID, dir, summary, false) 255 page, err := g.treePage(ctx, branch, newOID, dir, summary, false)
@@ -320,12 +329,15 @@ func (g *Generator) treePage(ctx context.Context, branch, oid, dir string, summa
320 if err != nil { 329 if err != nil {
321 return Page{}, err 330 return Page{}, err
322 } 331 }
332 g.decorateSubmodules(ctx, oid, dir, entries)
323 for i := range entries { 333 for i := range entries {
324 fullPath := path.Join(dir, entries[i].Name) 334 fullPath := path.Join(dir, entries[i].Name)
325 if entries[i].Type == "tree" { 335 if entries[i].Type == "tree" {
326 entries[i].URL = routeURL(g.BaseURL, path.Join("tree", branch, fullPath)) 336 entries[i].URL = routeURL(g.BaseURL, path.Join("tree", branchRouteSegment(branch), fullPath))
337 } else if entries[i].SubmoduleURL != "" {
338 entries[i].URL = entries[i].SubmoduleURL
327 } else { 339 } else {
328 entries[i].URL = routeURL(g.BaseURL, path.Join("blob", branch, fullPath)) 340 entries[i].URL = routeURL(g.BaseURL, path.Join("blob", branchRouteSegment(branch), fullPath))
329 } 341 }
330 } 342 }
331 if err := g.populateEntryCommits(ctx, oid, dir, entries, summary.CommitsURL); err != nil { 343 if err := g.populateEntryCommits(ctx, oid, dir, entries, summary.CommitsURL); err != nil {
@@ -333,11 +345,11 @@ func (g *Generator) treePage(ctx context.Context, branch, oid, dir string, summa
333 } 345 }
334 data := g.pageData("tree", g.RepoName, branch, summary) 346 data := g.pageData("tree", g.RepoName, branch, summary)
335 data.Path = dir 347 data.Path = dir
336 data.Breadcrumbs = g.breadcrumbs(branch, dir) 348 data.Breadcrumbs = g.breadcrumbs(branch, dir, "tree")
337 data.Entries = entries 349 data.Entries = entries
338 if dir != "" { 350 if dir != "" {
339 data.Title = path.Base(dir) + " · " + g.RepoName 351 data.Title = path.Base(dir) + " · " + g.RepoName
340 data.ParentURL = routeURL(g.BaseURL, path.Join("tree", branch, path.Dir(dir))) 352 data.ParentURL = routeURL(g.BaseURL, path.Join("tree", branchRouteSegment(branch), path.Dir(dir)))
341 } 353 }
342 if root { 354 if root {
343 data.Kind = "repo" 355 data.Kind = "repo"
@@ -355,7 +367,7 @@ func (g *Generator) treePage(ctx context.Context, branch, oid, dir string, summa
355 if root { 367 if root {
356 return Page{Body: body, ContentType: "text/html; charset=utf-8", Cache: siteCache, Root: true}, nil 368 return Page{Body: body, ContentType: "text/html; charset=utf-8", Cache: siteCache, Root: true}, nil
357 } 369 }
358 return Page{Route: path.Join("tree", branch, dir), Body: body, ContentType: "text/html; charset=utf-8", Cache: siteCache}, nil 370 return Page{Route: path.Join("tree", branchRouteSegment(branch), dir), Body: body, ContentType: "text/html; charset=utf-8", Cache: siteCache}, nil
359 } 371 }
360 372
361 func (g *Generator) populateEntryCommits(ctx context.Context, oid, dir string, entries []TreeEntry, commitsURL string) error { 373 func (g *Generator) populateEntryCommits(ctx context.Context, oid, dir string, entries []TreeEntry, commitsURL string) error {
@@ -423,18 +435,20 @@ func (g *Generator) blobPages(ctx context.Context, branch, oid string, entry Tre
423 return nil, err 435 return nil, err
424 } 436 }
425 } 437 }
426 rawRoute := path.Join("raw", branch, entry.Name) 438 rawRoute := path.Join("raw", branchRouteSegment(branch), entry.Name)
427 contentType := mime.TypeByExtension(path.Ext(entry.Name)) 439 contentType, previewImage := safeRawContentType(entry.Name, content)
428 if contentType == "" {
429 contentType = "application/octet-stream"
430 }
431 data := g.pageData("blob", path.Base(entry.Name)+" · "+g.RepoName, branch, summary) 440 data := g.pageData("blob", path.Base(entry.Name)+" · "+g.RepoName, branch, summary)
432 data.Path = entry.Name 441 data.Path = entry.Name
433 data.Breadcrumbs = g.breadcrumbs(branch, entry.Name) 442 data.Breadcrumbs = g.breadcrumbs(branch, entry.Name, "blob")
434 data.RawURL = routeURL(g.BaseURL, rawRoute) 443 data.RawURL = routeURL(g.BaseURL, rawRoute)
435 data.FileSize = int64(len(content)) 444 data.FileSize = int64(len(content))
436 data.IsImage = strings.HasPrefix(contentType, "image/") 445 data.IsSubmodule = entry.Type == "commit"
437 if data.IsImage { 446 data.SubmoduleURL = entry.SubmoduleURL
447 data.SubmoduleOID = entry.OID
448 data.IsImage = previewImage
449 if data.IsSubmodule {
450 data.Language = "Submodule"
451 } else if data.IsImage {
438 data.Language = "Image" 452 data.Language = "Image"
439 } else if bytes.IndexByte(content, 0) >= 0 || !utf8.Valid(content) { 453 } else if bytes.IndexByte(content, 0) >= 0 || !utf8.Valid(content) {
440 data.Language = "Binary" 454 data.Language = "Binary"
@@ -460,11 +474,28 @@ func (g *Generator) blobPages(ctx context.Context, branch, oid string, entry Tre
460 return nil, err 474 return nil, err
461 } 475 }
462 return []Page{ 476 return []Page{
463 {Route: path.Join("blob", branch, entry.Name), Body: body, ContentType: "text/html; charset=utf-8", Cache: siteCache}, 477 {Route: path.Join("blob", branchRouteSegment(branch), entry.Name), Body: body, ContentType: "text/html; charset=utf-8", Cache: siteCache},
464 {Route: rawRoute, Body: content, ContentType: contentType, Cache: rawCache}, 478 {Route: rawRoute, Body: content, ContentType: contentType, Cache: rawCache},
465 }, nil 479 }, nil
466 } 480 }
467 481
482 // Raw files share an origin with the generated repository browser. Serving
483 // user-controlled HTML, JavaScript, or SVG with an executable media type would
484 // let a repository run script in that origin, so only inert raster formats are
485 // previewed as images. Other UTF-8 files are deliberately served as plain text.
486 func safeRawContentType(filename string, content []byte) (string, bool) {
487 contentType := mime.TypeByExtension(path.Ext(filename))
488 mediaType, _, _ := mime.ParseMediaType(contentType)
489 switch mediaType {
490 case "image/avif", "image/bmp", "image/gif", "image/jpeg", "image/png", "image/webp", "image/x-icon", "image/vnd.microsoft.icon":
491 return contentType, true
492 }
493 if bytes.IndexByte(content, 0) < 0 && utf8.Valid(content) {
494 return "text/plain; charset=utf-8", false
495 }
496 return "application/octet-stream", false
497 }
498
468 func (g *Generator) readme(ctx context.Context, oid string, entries []TreeEntry) (string, template.HTML, error) { 499 func (g *Generator) readme(ctx context.Context, oid string, entries []TreeEntry) (string, template.HTML, error) {
469 for _, entry := range entries { 500 for _, entry := range entries {
470 if entry.Type != "blob" || !strings.HasPrefix(strings.ToLower(entry.Name), "readme") { 501 if entry.Type != "blob" || !strings.HasPrefix(strings.ToLower(entry.Name), "readme") {
@@ -501,6 +532,7 @@ func renderMarkdown(content []byte) (template.HTML, error) {
501 if err := markdown.Convert(content, &rendered); err != nil { 532 if err := markdown.Convert(content, &rendered); err != nil {
502 return "", err 533 return "", err
503 } 534 }
535 // #nosec G203 -- Goldmark's safe renderer filters raw HTML and dangerous URLs.
504 return template.HTML(rendered.String()), nil 536 return template.HTML(rendered.String()), nil
505 } 537 }
506 538
@@ -528,6 +560,7 @@ func highlight(filename string, content []byte) (template.HTML, string, error) {
528 if err := formatter.Format(&rendered, styles.Get("github"), iterator); err != nil { 560 if err := formatter.Format(&rendered, styles.Get("github"), iterator); err != nil {
529 return "", "", err 561 return "", "", err
530 } 562 }
563 // #nosec G203 -- Chroma escapes source tokens before producing this HTML.
531 return template.HTML(rendered.String()), lexer.Config().Name, nil 564 return template.HTML(rendered.String()), lexer.Config().Name, nil
532 } 565 }
533 566
@@ -560,7 +593,7 @@ func (g *Generator) pageData(kind, title, branch string, summary branchSummary)
560 CommitsURL: summary.CommitsURL, 593 CommitsURL: summary.CommitsURL,
561 CommitGroups: summary.Groups, 594 CommitGroups: summary.Groups,
562 BranchesURL: routeURL(g.BaseURL, ".dumbforge/repository.json"), 595 BranchesURL: routeURL(g.BaseURL, ".dumbforge/repository.json"),
563 FilesURL: routeURL(g.BaseURL, path.Join(".dumbforge/files", branch+".json")), 596 FilesURL: routeURL(g.BaseURL, path.Join(".dumbforge/files", branchRouteSegment(branch)+".json")),
564 DefaultBranch: g.DefaultBranch, 597 DefaultBranch: g.DefaultBranch,
565 GitHubImportURL: "https://github.com/new/import", 598 GitHubImportURL: "https://github.com/new/import",
566 Description: summary.Repository.Description, 599 Description: summary.Repository.Description,
@@ -580,7 +613,7 @@ func (g *Generator) commitsPage(branch string, summary branchSummary) (Page, err
580 return Page{}, err 613 return Page{}, err
581 } 614 }
582 return Page{ 615 return Page{
583 Route: path.Join("commits", branch), 616 Route: path.Join("commits", branchRouteSegment(branch)),
584 Body: body, 617 Body: body,
585 ContentType: "text/html; charset=utf-8", 618 ContentType: "text/html; charset=utf-8",
586 Cache: siteCache, 619 Cache: siteCache,
@@ -613,7 +646,7 @@ func (g *Generator) listTreeRecursive(ctx context.Context, oid string) ([]TreeEn
613 } 646 }
614 647
615 func (g *Generator) entry(ctx context.Context, oid, name string) (TreeEntry, error) { 648 func (g *Generator) entry(ctx context.Context, oid, name string) (TreeEntry, error) {
616 out, err := g.Git.Run(ctx, "ls-tree", "-z", "-l", oid, "--", name) 649 out, err := g.Git.Run(ctx, "--literal-pathspecs", "ls-tree", "-z", "-l", oid, "--", name)
617 if err != nil { 650 if err != nil {
618 return TreeEntry{}, err 651 return TreeEntry{}, err
619 } 652 }
@@ -674,7 +707,7 @@ func sortTree(entries []TreeEntry) {
674 }) 707 })
675 } 708 }
676 709
677 func (g *Generator) breadcrumbs(branch, filePath string) []Crumb { 710 func (g *Generator) breadcrumbs(branch, filePath, leafKind string) []Crumb {
678 crumbs := []Crumb{{Name: g.RepoName, URL: g.BaseURL}} 711 crumbs := []Crumb{{Name: g.RepoName, URL: g.BaseURL}}
679 parts := strings.Split(strings.Trim(filePath, "/"), "/") 712 parts := strings.Split(strings.Trim(filePath, "/"), "/")
680 for i, part := range parts { 713 for i, part := range parts {
@@ -683,10 +716,10 @@ func (g *Generator) breadcrumbs(branch, filePath string) []Crumb {
683 } 716 }
684 prefix := path.Join(parts[:i+1]...) 717 prefix := path.Join(parts[:i+1]...)
685 routeKind := "tree" 718 routeKind := "tree"
686 if i == len(parts)-1 && path.Ext(filePath) != "" { 719 if i == len(parts)-1 {
687 routeKind = "blob" 720 routeKind = leafKind
688 } 721 }
689 crumbs = append(crumbs, Crumb{Name: part, URL: routeURL(g.BaseURL, path.Join(routeKind, branch, prefix))}) 722 crumbs = append(crumbs, Crumb{Name: part, URL: routeURL(g.BaseURL, path.Join(routeKind, branchRouteSegment(branch), prefix))})
690 } 723 }
691 return crumbs 724 return crumbs
692 } 725 }
@@ -702,6 +735,12 @@ func routeURL(base, route string) string {
702 return strings.TrimRight(base, "/") + "/" + strings.Join(parts, "/") 735 return strings.TrimRight(base, "/") + "/" + strings.Join(parts, "/")
703 } 736 }
704 737
738 // Git ref names cannot contain '~', so it is an unambiguous stand-in for '/'
739 // when a branch name must occupy one component of the static URL hierarchy.
740 func branchRouteSegment(branch string) string {
741 return strings.ReplaceAll(branch, "/", "~")
742 }
743
705 func addAncestorDirs(dirs map[string]struct{}, filePath string) { 744 func addAncestorDirs(dirs map[string]struct{}, filePath string) {
706 dir := path.Dir(filePath) 745 dir := path.Dir(filePath)
707 for dir != "." && dir != "/" && dir != "" { 746 for dir != "." && dir != "/" && dir != "" {
Modifiedinternal/site/site_test.go +100−0
@@ -17,8 +17,11 @@ func TestFullAndIncrementalBuild(t *testing.T) {
17 runGit(t, dir, "config", "user.name", "Site Test") 17 runGit(t, dir, "config", "user.name", "Site Test")
18 runGit(t, dir, "config", "user.email", "[email protected]") 18 runGit(t, dir, "config", "user.email", "[email protected]")
19 write(t, dir, "README.md", "# Hello bucket\n") 19 write(t, dir, "README.md", "# Hello bucket\n")
20 write(t, dir, "LICENSE", "test license\n")
21 write(t, dir, "danger.html", "<!doctype html><script>alert('nope')</script>\n")
20 write(t, dir, "docs/guide.md", "# Guide\n\n- first\n- second\n") 22 write(t, dir, "docs/guide.md", "# Guide\n\n- first\n- second\n")
21 write(t, dir, "src/main.go", "package main\n\nfunc main() {}\n") 23 write(t, dir, "src/main.go", "package main\n\nfunc main() {}\n")
24 write(t, dir, "vector.svg", `<svg xmlns="http://www.w3.org/2000/svg"><script>alert('nope')</script></svg>`)
22 runGit(t, dir, "add", ".") 25 runGit(t, dir, "add", ".")
23 runGit(t, dir, "commit", "-m", "initial") 26 runGit(t, dir, "commit", "-m", "initial")
24 first := outputGit(t, dir, "rev-parse", "HEAD") 27 first := outputGit(t, dir, "rev-parse", "HEAD")
@@ -47,10 +50,14 @@ func TestFullAndIncrementalBuild(t *testing.T) {
47 assertPage(t, full, "", "octicon-folder") 50 assertPage(t, full, "", "octicon-folder")
48 assertPage(t, full, "blob/main/src/main.go", "chroma") 51 assertPage(t, full, "blob/main/src/main.go", "chroma")
49 assertPage(t, full, "blob/main/src/main.go", "data-file-tree") 52 assertPage(t, full, "blob/main/src/main.go", "data-file-tree")
53 assertPage(t, full, "blob/main/LICENSE", `href="https://example.invalid/repo.git/blob/main/LICENSE"`)
50 assertPage(t, full, "blob/main/docs/guide.md", `<article class="markdown-file">`) 54 assertPage(t, full, "blob/main/docs/guide.md", `<article class="markdown-file">`)
51 assertPage(t, full, "blob/main/docs/guide.md", `<h1 id="guide">Guide</h1>`) 55 assertPage(t, full, "blob/main/docs/guide.md", `<h1 id="guide">Guide</h1>`)
52 assertPage(t, full, "blob/main/docs/guide.md", "<li>first</li>") 56 assertPage(t, full, "blob/main/docs/guide.md", "<li>first</li>")
53 assertPageDoesNotContain(t, full, "blob/main/docs/guide.md", `<div class="code-view">`) 57 assertPageDoesNotContain(t, full, "blob/main/docs/guide.md", `<div class="code-view">`)
58 assertContentType(t, full, "raw/main/danger.html", "text/plain; charset=utf-8")
59 assertContentType(t, full, "raw/main/vector.svg", "text/plain; charset=utf-8")
60 assertPageDoesNotContain(t, full, "blob/main/vector.svg", `<div class="image-preview">`)
54 assertPage(t, full, ".dumbforge/assets/gabriel-mark.svg", "<svg") 61 assertPage(t, full, ".dumbforge/assets/gabriel-mark.svg", "<svg")
55 assertPage(t, full, ".dumbforge/assets/gabriel-mark.png", "PNG") 62 assertPage(t, full, ".dumbforge/assets/gabriel-mark.png", "PNG")
56 assertPage(t, full, "tree/main/src", "main.go") 63 assertPage(t, full, "tree/main/src", "main.go")
@@ -82,6 +89,77 @@ func TestFullAndIncrementalBuild(t *testing.T) {
82 assertPage(t, incremental, "commits/main", "change one file") 89 assertPage(t, incremental, "commits/main", "change one file")
83 } 90 }
84 91
92 func TestSlashBranchUsesUnambiguousRoutes(t *testing.T) {
93 dir := t.TempDir()
94 runGit(t, dir, "init", "-b", "main")
95 runGit(t, dir, "config", "user.name", "Site Test")
96 runGit(t, dir, "config", "user.email", "[email protected]")
97 write(t, dir, "docs/guide.md", "# Guide\n")
98 runGit(t, dir, "add", ".")
99 runGit(t, dir, "commit", "-m", "initial")
100 oid := outputGit(t, dir, "rev-parse", "HEAD")
101
102 generator, err := New(gitutil.Git{Dir: dir}, "https://example.invalid/repo.git", "repo.git", "owner")
103 if err != nil {
104 t.Fatal(err)
105 }
106 build, err := generator.BuildBranch(context.Background(), "feature/demo", "", oid, false)
107 if err != nil {
108 t.Fatal(err)
109 }
110 assertPage(t, build, "tree/feature~demo", "feature/demo")
111 assertPage(t, build, "blob/feature~demo/docs/guide.md", "Guide")
112 assertPage(t, build, "commits/feature~demo", "Commit history")
113 assertPage(t, build, ".dumbforge/files/feature~demo.json", `/blob/feature~demo/docs/guide.md`)
114 for _, page := range build.Pages {
115 if strings.Contains(page.Route, "feature/demo") {
116 t.Fatalf("ambiguous branch route generated: %q", page.Route)
117 }
118 }
119 }
120
121 func TestMarkdownDoesNotPassThroughActiveContent(t *testing.T) {
122 rendered, err := renderMarkdown([]byte("<script>alert('nope')</script>\n\n[bad](javascript:alert('nope'))\n"))
123 if err != nil {
124 t.Fatal(err)
125 }
126 result := strings.ToLower(string(rendered))
127 if strings.Contains(result, "<script") || strings.Contains(result, "javascript:") {
128 t.Fatalf("unsafe Markdown output: %s", result)
129 }
130 }
131
132 func TestSubmoduleEntryRendersWithoutLocalSubmoduleObject(t *testing.T) {
133 dir := t.TempDir()
134 runGit(t, dir, "init", "-b", "main")
135 runGit(t, dir, "config", "user.name", "Site Test")
136 runGit(t, dir, "config", "user.email", "[email protected]")
137 write(t, dir, ".gitmodules", "[submodule \"example\"]\n\tpath = vendor/example\n\turl = https://github.com/example/project.git\n")
138 runGit(t, dir, "add", ".gitmodules")
139 runGit(t, dir, "update-index", "--add", "--cacheinfo", "160000,1111111111111111111111111111111111111111,vendor/example")
140 runGit(t, dir, "commit", "-m", "add submodule")
141 oid := outputGit(t, dir, "rev-parse", "HEAD")
142
143 generator, err := New(gitutil.Git{Dir: dir}, "https://example.invalid/repo.git", "repo.git", "owner")
144 if err != nil {
145 t.Fatal(err)
146 }
147 build, err := generator.BuildBranch(context.Background(), "main", "", oid, true)
148 if err != nil {
149 t.Fatal(err)
150 }
151 assertPage(t, build, "blob/main/vendor/example", "Points to commit <code>1111111111111111111111111111111111111111</code>")
152 assertPage(t, build, "blob/main/vendor/example", "https://github.com/example/project/commit/1111111111111111111111111111111111111111")
153 assertPage(t, build, "tree/main/vendor", "https://github.com/example/project/commit/1111111111111111111111111111111111111111")
154 assertContentType(t, build, "raw/main/vendor/example", "text/plain; charset=utf-8")
155 }
156
157 func TestRelativeSubmoduleURLResolvesBesideCurrentRepository(t *testing.T) {
158 if got := browserRepositoryURL("https://forge.example/group/project.git", "../dependency.git"); got != "https://forge.example/group/dependency.git" {
159 t.Fatalf("relative submodule URL = %q", got)
160 }
161 }
162
85 func TestRepositoryNavigationBuild(t *testing.T) { 163 func TestRepositoryNavigationBuild(t *testing.T) {
86 generator, err := New(gitutil.Git{}, "https://example.invalid/repo.git", "repo.git", "owner") 164 generator, err := New(gitutil.Git{}, "https://example.invalid/repo.git", "repo.git", "owner")
87 if err != nil { 165 if err != nil {
@@ -109,6 +187,15 @@ func TestReadmeMetadataFallbacks(t *testing.T) {
109 } 187 }
110 } 188 }
111 189
190 func TestRepositoryURLKeepsGitSuffixForDumbforge(t *testing.T) {
191 if got := normalizeRepositoryURL("git+https://dumbforge.dev/dumbforge.git"); got != "https://dumbforge.dev/dumbforge.git" {
192 t.Fatalf("dumbforge repository URL = %q", got)
193 }
194 if got := normalizeRepositoryURL("git+https://github.com/example/project.git"); got != "https://github.com/example/project" {
195 t.Fatalf("GitHub repository URL = %q", got)
196 }
197 }
198
112 func TestGravatarUsesNormalizedSHA256(t *testing.T) { 199 func TestGravatarUsesNormalizedSHA256(t *testing.T) {
113 url := gravatarURL(" [email protected] ", "User Example") 200 url := gravatarURL(" [email protected] ", "User Example")
114 if !strings.Contains(url, "https://gravatar.com/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514") { 201 if !strings.Contains(url, "https://gravatar.com/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514") {
@@ -145,6 +232,19 @@ func assertPageDoesNotContain(t *testing.T, build Build, route, unwanted string)
145 t.Fatalf("page %q was not generated", route) 232 t.Fatalf("page %q was not generated", route)
146 } 233 }
147 234
235 func assertContentType(t *testing.T, build Build, route, want string) {
236 t.Helper()
237 for _, page := range build.Pages {
238 if page.Route == route {
239 if page.ContentType != want {
240 t.Fatalf("page %q content type = %q, want %q", route, page.ContentType, want)
241 }
242 return
243 }
244 }
245 t.Fatalf("page %q was not generated", route)
246 }
247
148 func write(t *testing.T, dir, name, contents string) { 248 func write(t *testing.T, dir, name, contents string) {
149 t.Helper() 249 t.Helper()
150 filename := filepath.Join(dir, name) 250 filename := filepath.Join(dir, name)
Addedinternal/site/submodule.go +152−0
@@ -0,0 +1,152 @@
1 package site
2
3 import (
4 "bytes"
5 "context"
6 "net/url"
7 "path"
8 "strings"
9 )
10
11 type submoduleConfig struct {
12 Path string
13 URL string
14 }
15
16 func (g *Generator) decorateSubmodules(ctx context.Context, oid, dir string, entries []TreeEntry) {
17 repositories := g.submoduleRepositories(ctx, oid)
18 for i := range entries {
19 if entries[i].Type != "commit" {
20 continue
21 }
22 filePath := path.Join(dir, entries[i].Name)
23 if repository := repositories[filePath]; repository != "" {
24 entries[i].SubmoduleURL = submoduleTargetURL(repository, entries[i].OID)
25 }
26 }
27 }
28
29 func (g *Generator) submoduleRepositories(ctx context.Context, oid string) map[string]string {
30 g.submoduleMu.Lock()
31 if cached, ok := g.submoduleCache[oid]; ok {
32 g.submoduleMu.Unlock()
33 return cached
34 }
35 g.submoduleMu.Unlock()
36
37 result := map[string]string{}
38 out, err := g.Git.Run(ctx, "config", "-z", "--blob", oid+":.gitmodules", "--get-regexp", `^submodule\..*\.(path|url)$`)
39 if err == nil {
40 configs := map[string]*submoduleConfig{}
41 for _, record := range bytes.Split(out, []byte{0}) {
42 key, value, ok := bytes.Cut(record, []byte{'\n'})
43 if !ok {
44 continue
45 }
46 name := string(key)
47 var field string
48 switch {
49 case strings.HasSuffix(name, ".path"):
50 name = strings.TrimSuffix(name, ".path")
51 field = "path"
52 case strings.HasSuffix(name, ".url"):
53 name = strings.TrimSuffix(name, ".url")
54 field = "url"
55 default:
56 continue
57 }
58 config := configs[name]
59 if config == nil {
60 config = &submoduleConfig{}
61 configs[name] = config
62 }
63 if field == "path" {
64 config.Path = string(value)
65 } else {
66 config.URL = string(value)
67 }
68 }
69 for _, config := range configs {
70 if config.Path == "" {
71 continue
72 }
73 if repository := browserRepositoryURL(g.CloneURL, config.URL); repository != "" {
74 result[config.Path] = repository
75 }
76 }
77 }
78
79 g.submoduleMu.Lock()
80 if g.submoduleCache == nil {
81 g.submoduleCache = map[string]map[string]string{}
82 }
83 g.submoduleCache[oid] = result
84 g.submoduleMu.Unlock()
85 return result
86 }
87
88 func browserRepositoryURL(cloneURL, raw string) string {
89 raw = strings.TrimSpace(strings.TrimPrefix(raw, "git+"))
90 if raw == "" {
91 return ""
92 }
93 if strings.HasPrefix(raw, "./") || strings.HasPrefix(raw, "../") {
94 base, err := url.Parse(strings.TrimRight(cloneURL, "/") + "/")
95 if err != nil || (base.Scheme != "http" && base.Scheme != "https") || base.Host == "" {
96 return ""
97 }
98 reference, err := url.Parse(raw)
99 if err != nil {
100 return ""
101 }
102 return base.ResolveReference(reference).String()
103 }
104 if strings.HasPrefix(raw, "ssh://") {
105 parsed, err := url.Parse(raw)
106 if err != nil || parsed.Host == "" {
107 return ""
108 }
109 parsed.Scheme = "https"
110 parsed.User = nil
111 return parsed.String()
112 }
113 if strings.HasPrefix(raw, "git://") {
114 raw = "https://" + strings.TrimPrefix(raw, "git://")
115 } else if !strings.Contains(raw, "://") {
116 at := strings.IndexByte(raw, '@')
117 colon := strings.IndexByte(raw, ':')
118 if at >= 0 && colon > at {
119 raw = "https://" + raw[at+1:colon] + "/" + raw[colon+1:]
120 }
121 }
122 parsed, err := url.Parse(raw)
123 if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" || parsed.User != nil {
124 return ""
125 }
126 parsed.RawQuery = ""
127 parsed.Fragment = ""
128 return parsed.String()
129 }
130
131 func submoduleTargetURL(repository string, oid string) string {
132 parsed, err := url.Parse(repository)
133 if err != nil || parsed.Host == "" {
134 return repository
135 }
136 host := strings.ToLower(parsed.Hostname())
137 commitRoute := ""
138 switch host {
139 case "github.com", "codeberg.org", "gitea.com":
140 commitRoute = "commit"
141 case "gitlab.com":
142 commitRoute = "-/commit"
143 case "bitbucket.org":
144 commitRoute = "commits"
145 }
146 if commitRoute == "" {
147 return repository
148 }
149 parsed.Path = strings.TrimSuffix(parsed.Path, ".git")
150 parsed.Path = path.Join(parsed.Path, commitRoute, oid)
151 return parsed.String()
152 }
Modifiedinternal/site/template.go +11−6
@@ -134,7 +134,8 @@ const pageTemplate = `<!doctype html>
134 <div><strong>{{.Path}}</strong><span>{{humanSize .FileSize}} · {{.Language}}</span></div> 134 <div><strong>{{.Path}}</strong><span>{{humanSize .FileSize}} · {{.Language}}</span></div>
135 <div class="blob-actions"><a href="{{.RawURL}}">Raw</a><button type="button" data-copy="{{.RawURL}}"><span data-copy-icon>{{icon "copy"}}</span><span data-copied-icon hidden>{{icon "check"}}</span><span data-copy-label>Copy link</span></button></div> 135 <div class="blob-actions"><a href="{{.RawURL}}">Raw</a><button type="button" data-copy="{{.RawURL}}"><span data-copy-icon>{{icon "copy"}}</span><span data-copied-icon hidden>{{icon "check"}}</span><span data-copy-label>Copy link</span></button></div>
136 </div> 136 </div>
137 {{if .IsImage}}<div class="image-preview"><img src="{{.RawURL}}" alt="{{.Path}}"></div> 137 {{if .IsSubmodule}}<div class="binary-notice"><span>{{icon "repo"}}</span><strong>Submodule</strong><p>Points to commit <code>{{.SubmoduleOID}}</code>.</p>{{if .SubmoduleURL}}<a href="{{.SubmoduleURL}}">Open submodule</a>{{end}}</div>
138 {{else if .IsImage}}<div class="image-preview"><img src="{{.RawURL}}" alt="{{.Path}}"></div>
138 {{else if .IsMarkdown}}<article class="markdown-file"><div class="markdown-body">{{.Markdown}}</div></article> 139 {{else if .IsMarkdown}}<article class="markdown-file"><div class="markdown-body">{{.Markdown}}</div></article>
139 {{else if .Code}}<div class="code-view">{{.Code}}</div> 140 {{else if .Code}}<div class="code-view">{{.Code}}</div>
140 {{else}}<div class="binary-notice"><span>{{icon "file"}}</span><strong>Preview unavailable</strong><p>This file is binary or too large to render safely.</p><a href="{{.RawURL}}">Download raw file</a></div>{{end}} 141 {{else}}<div class="binary-notice"><span>{{icon "file"}}</span><strong>Preview unavailable</strong><p>This file is binary or too large to render safely.</p><a href="{{.RawURL}}">Download raw file</a></div>{{end}}
@@ -233,16 +234,20 @@ const pageTemplate = `<!doctype html>
233 }); 234 });
234 return body.dataset.baseUrl.replace(/\/$/, '') + (segments.length ? '/' + segments.join('/') : ''); 235 return body.dataset.baseUrl.replace(/\/$/, '') + (segments.length ? '/' + segments.join('/') : '');
235 } 236 }
237 function branchRouteSegment(branch) {
238 return String(branch || '').replace(/\//g, '~');
239 }
236 function branchTarget(branch, defaultBranch) { 240 function branchTarget(branch, defaultBranch) {
237 var kind = body.dataset.routeKind; 241 var kind = body.dataset.routeKind;
238 var filePath = body.dataset.routePath; 242 var filePath = body.dataset.routePath;
239 if (kind === 'repo') return branch === defaultBranch ? body.dataset.baseUrl : encodedRoute(['tree', branch]); 243 var branchRoute = branchRouteSegment(branch);
244 if (kind === 'repo') return branch === defaultBranch ? body.dataset.baseUrl : encodedRoute(['tree', branchRoute]);
240 if (kind === 'tree') { 245 if (kind === 'tree') {
241 if (!filePath && branch === defaultBranch) return body.dataset.baseUrl; 246 if (!filePath && branch === defaultBranch) return body.dataset.baseUrl;
242 return encodedRoute(['tree', branch, filePath]); 247 return encodedRoute(['tree', branchRoute, filePath]);
243 } 248 }
244 if (kind === 'blob') return encodedRoute(['blob', branch, filePath]); 249 if (kind === 'blob') return encodedRoute(['blob', branchRoute, filePath]);
245 if (kind === 'commits') return encodedRoute(['commits', branch]); 250 if (kind === 'commits') return encodedRoute(['commits', branchRoute]);
246 return body.dataset.baseUrl; 251 return body.dataset.baseUrl;
247 } 252 }
248 var branchMenu = one('[data-branch-menu]'); 253 var branchMenu = one('[data-branch-menu]');
@@ -476,7 +481,7 @@ const pageTemplate = `<!doctype html>
476 <div class="tree-rows"> 481 <div class="tree-rows">
477 {{if .ParentURL}}<div class="tree-row parent-row"><span class="file-icon">{{icon "back"}}</span><a class="file-name" href="{{.ParentURL}}">..</a><span></span><span></span></div>{{end}} 482 {{if .ParentURL}}<div class="tree-row parent-row"><span class="file-icon">{{icon "back"}}</span><a class="file-name" href="{{.ParentURL}}">..</a><span></span><span></span></div>{{end}}
478 {{range .Entries}}<div class="tree-row"> 483 {{range .Entries}}<div class="tree-row">
479 {{if eq .Type "tree"}}<span class="file-icon folder">{{icon "folder"}}</span>{{else}}<span class="file-icon">{{icon "file"}}</span>{{end}} 484 {{if eq .Type "tree"}}<span class="file-icon folder">{{icon "folder"}}</span>{{else if eq .Type "commit"}}<span class="file-icon">{{icon "repo"}}</span>{{else}}<span class="file-icon">{{icon "file"}}</span>{{end}}
480 <a class="file-name" href="{{.URL}}">{{.Name}}</a> 485 <a class="file-name" href="{{.URL}}">{{.Name}}</a>
481 <a class="row-message" href="{{.CommitURL}}" title="{{.CommitMessage}}">{{.CommitMessage}}</a> 486 <a class="row-message" href="{{.CommitURL}}" title="{{.CommitMessage}}">{{.CommitMessage}}</a>
482 <span class="file-size">{{humanSize .Size}}</span> 487 <span class="file-size">{{humanSize .Size}}</span>
Modifiednpm/launcher/run.cjs +6−6
@@ -4,12 +4,12 @@ const path = require("node:path");
4 const { spawnSync } = require("node:child_process"); 4 const { spawnSync } = require("node:child_process");
5 5
6 const packages = { 6 const packages = {
7 "darwin-arm64": "@dumbforge/darwin-arm64", 7 "darwin-arm64": "dumbforge-darwin-arm64",
8 "darwin-x64": "@dumbforge/darwin-x64", 8 "darwin-x64": "dumbforge-darwin-x64",
9 "linux-arm64": "@dumbforge/linux-arm64", 9 "linux-arm64": "dumbforge-linux-arm64",
10 "linux-x64": "@dumbforge/linux-x64", 10 "linux-x64": "dumbforge-linux-x64",
11 "win32-arm64": "@dumbforge/win32-arm64", 11 "win32-arm64": "dumbforge-win32-arm64",
12 "win32-x64": "@dumbforge/win32-x64" 12 "win32-x64": "dumbforge-win32-x64"
13 }; 13 };
14 14
15 module.exports = function run(remoteHelper) { 15 module.exports = function run(remoteHelper) {
Modifiednpm/platforms/darwin-arm64/package.json +3−3
@@ -1,10 +1,10 @@
1 { 1 {
2 "name": "@dumbforge/darwin-arm64", 2 "name": "dumbforge-darwin-arm64",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "dumbforge native binary for macOS ARM64", 4 "description": "dumbforge native binary for macOS ARM64",
5 "license": "MIT", 5 "license": "AGPL-3.0-only",
6 "os": ["darwin"], 6 "os": ["darwin"],
7 "cpu": ["arm64"], 7 "cpu": ["arm64"],
8 "files": ["bin"], 8 "files": ["bin", "LICENSE", "THIRD_PARTY_NOTICES.md", "THIRD_PARTY_LICENSES"],
9 "publishConfig": {"access": "public"} 9 "publishConfig": {"access": "public"}
10 } 10 }
Modifiednpm/platforms/darwin-x64/package.json +3−3
@@ -1,10 +1,10 @@
1 { 1 {
2 "name": "@dumbforge/darwin-x64", 2 "name": "dumbforge-darwin-x64",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "dumbforge native binary for macOS x64", 4 "description": "dumbforge native binary for macOS x64",
5 "license": "MIT", 5 "license": "AGPL-3.0-only",
6 "os": ["darwin"], 6 "os": ["darwin"],
7 "cpu": ["x64"], 7 "cpu": ["x64"],
8 "files": ["bin"], 8 "files": ["bin", "LICENSE", "THIRD_PARTY_NOTICES.md", "THIRD_PARTY_LICENSES"],
9 "publishConfig": {"access": "public"} 9 "publishConfig": {"access": "public"}
10 } 10 }
Modifiednpm/platforms/linux-arm64/package.json +3−3
@@ -1,10 +1,10 @@
1 { 1 {
2 "name": "@dumbforge/linux-arm64", 2 "name": "dumbforge-linux-arm64",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "dumbforge native binary for Linux ARM64", 4 "description": "dumbforge native binary for Linux ARM64",
5 "license": "MIT", 5 "license": "AGPL-3.0-only",
6 "os": ["linux"], 6 "os": ["linux"],
7 "cpu": ["arm64"], 7 "cpu": ["arm64"],
8 "files": ["bin"], 8 "files": ["bin", "LICENSE", "THIRD_PARTY_NOTICES.md", "THIRD_PARTY_LICENSES"],
9 "publishConfig": {"access": "public"} 9 "publishConfig": {"access": "public"}
10 } 10 }
Modifiednpm/platforms/linux-x64/package.json +3−3
@@ -1,10 +1,10 @@
1 { 1 {
2 "name": "@dumbforge/linux-x64", 2 "name": "dumbforge-linux-x64",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "dumbforge native binary for Linux x64", 4 "description": "dumbforge native binary for Linux x64",
5 "license": "MIT", 5 "license": "AGPL-3.0-only",
6 "os": ["linux"], 6 "os": ["linux"],
7 "cpu": ["x64"], 7 "cpu": ["x64"],
8 "files": ["bin"], 8 "files": ["bin", "LICENSE", "THIRD_PARTY_NOTICES.md", "THIRD_PARTY_LICENSES"],
9 "publishConfig": {"access": "public"} 9 "publishConfig": {"access": "public"}
10 } 10 }
Modifiednpm/platforms/win32-arm64/package.json +3−3
@@ -1,10 +1,10 @@
1 { 1 {
2 "name": "@dumbforge/win32-arm64", 2 "name": "dumbforge-win32-arm64",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "dumbforge native binary for Windows ARM64", 4 "description": "dumbforge native binary for Windows ARM64",
5 "license": "MIT", 5 "license": "AGPL-3.0-only",
6 "os": ["win32"], 6 "os": ["win32"],
7 "cpu": ["arm64"], 7 "cpu": ["arm64"],
8 "files": ["bin"], 8 "files": ["bin", "LICENSE", "THIRD_PARTY_NOTICES.md", "THIRD_PARTY_LICENSES"],
9 "publishConfig": {"access": "public"} 9 "publishConfig": {"access": "public"}
10 } 10 }
Modifiednpm/platforms/win32-x64/package.json +3−3
@@ -1,10 +1,10 @@
1 { 1 {
2 "name": "@dumbforge/win32-x64", 2 "name": "dumbforge-win32-x64",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "dumbforge native binary for Windows x64", 4 "description": "dumbforge native binary for Windows x64",
5 "license": "MIT", 5 "license": "AGPL-3.0-only",
6 "os": ["win32"], 6 "os": ["win32"],
7 "cpu": ["x64"], 7 "cpu": ["x64"],
8 "files": ["bin"], 8 "files": ["bin", "LICENSE", "THIRD_PARTY_NOTICES.md", "THIRD_PARTY_LICENSES"],
9 "publishConfig": {"access": "public"} 9 "publishConfig": {"access": "public"}
10 } 10 }
Modifiedpackage.json +11−8
@@ -2,7 +2,9 @@
2 "name": "dumbforge", 2 "name": "dumbforge",
3 "version": "0.1.0", 3 "version": "0.1.0",
4 "description": "Push Git repositories to S3-compatible buckets and clone them over static dumb HTTP", 4 "description": "Push Git repositories to S3-compatible buckets and clone them over static dumb HTTP",
5 "license": "AGPLv3", 5 "author": "Nick Faro",
6 "license": "AGPL-3.0-only",
7 "homepage": "https://dumbforge.dev/dumbforge.git",
6 "repository": { 8 "repository": {
7 "type": "git", 9 "type": "git",
8 "url": "git+https://dumbforge.dev/dumbforge.git" 10 "url": "git+https://dumbforge.dev/dumbforge.git"
@@ -18,19 +20,20 @@
18 "npm/launcher", 20 "npm/launcher",
19 "README.md", 21 "README.md",
20 "LICENSE", 22 "LICENSE",
21 "THIRD_PARTY_NOTICES.md" 23 "THIRD_PARTY_NOTICES.md",
24 "THIRD_PARTY_LICENSES"
22 ], 25 ],
23 "bin": { 26 "bin": {
24 "dumbforge": "npm/launcher/dumbforge.cjs", 27 "dumbforge": "npm/launcher/dumbforge.cjs",
25 "git-remote-dumbforge": "npm/launcher/git-remote-dumbforge.cjs" 28 "git-remote-dumbforge": "npm/launcher/git-remote-dumbforge.cjs"
26 }, 29 },
27 "optionalDependencies": { 30 "optionalDependencies": {
28 "@dumbforge/darwin-arm64": "0.1.0", 31 "dumbforge-darwin-arm64": "0.1.0",
29 "@dumbforge/darwin-x64": "0.1.0", 32 "dumbforge-darwin-x64": "0.1.0",
30 "@dumbforge/linux-arm64": "0.1.0", 33 "dumbforge-linux-arm64": "0.1.0",
31 "@dumbforge/linux-x64": "0.1.0", 34 "dumbforge-linux-x64": "0.1.0",
32 "@dumbforge/win32-arm64": "0.1.0", 35 "dumbforge-win32-arm64": "0.1.0",
33 "@dumbforge/win32-x64": "0.1.0" 36 "dumbforge-win32-x64": "0.1.0"
34 }, 37 },
35 "engines": { 38 "engines": {
36 "node": ">=18" 39 "node": ">=18"
Modifiedscripts/build-npm-packages.sh +13−2
@@ -4,15 +4,26 @@ set -euo pipefail
4 version="${1:-0.1.0}" 4 version="${1:-0.1.0}"
5 project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" 5 project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6 output_dir="$project_root/dist/npm" 6 output_dir="$project_root/dist/npm"
7 stage_root="$(mktemp -d "${TMPDIR:-/tmp}/dumbforge-npm.XXXXXX")"
7 mkdir -p "$output_dir" 8 mkdir -p "$output_dir"
8 9
10 cleanup() {
11 rm -rf "$stage_root"
12 }
13 trap cleanup EXIT
14
9 build_target() { 15 build_target() {
10 local goos="$1" 16 local goos="$1"
11 local goarch="$2" 17 local goarch="$2"
12 local npm_platform="$3" 18 local npm_platform="$3"
13 local suffix="$4" 19 local suffix="$4"
14 local package_dir="$project_root/npm/platforms/$npm_platform" 20 local package_source="$project_root/npm/platforms/$npm_platform"
21 local package_dir="$stage_root/$npm_platform"
15 mkdir -p "$package_dir/bin" 22 mkdir -p "$package_dir/bin"
23 cp "$package_source/package.json" "$package_dir/package.json"
24 cp "$project_root/LICENSE" "$package_dir/LICENSE"
25 cp "$project_root/THIRD_PARTY_NOTICES.md" "$package_dir/THIRD_PARTY_NOTICES.md"
26 cp -R "$project_root/THIRD_PARTY_LICENSES" "$package_dir/THIRD_PARTY_LICENSES"
16 CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build \ 27 CGO_ENABLED=0 GOOS="$goos" GOARCH="$goarch" go build \
17 -trimpath \ 28 -trimpath \
18 -ldflags "-s -w -X main.version=$version" \ 29 -ldflags "-s -w -X main.version=$version" \
@@ -27,7 +38,7 @@ build_target linux amd64 linux-x64 ""
27 build_target windows arm64 win32-arm64 ".exe" 38 build_target windows arm64 win32-arm64 ".exe"
28 build_target windows amd64 win32-x64 ".exe" 39 build_target windows amd64 win32-x64 ".exe"
29 40
30 for package_dir in "$project_root"/npm/platforms/*; do 41 for package_dir in "$stage_root"/*; do
31 npm pack "$package_dir" --pack-destination "$output_dir" 42 npm pack "$package_dir" --pack-destination "$output_dir"
32 done 43 done
33 npm pack "$project_root" --pack-destination "$output_dir" 44 npm pack "$project_root" --pack-destination "$output_dir"