Commit Graph

20 Commits

Author SHA1 Message Date
Steeve Chailloux
4f97acfe0f fix git http_proxy ignored
Signed-off-by: Steeve Chailloux <me@steeve.io>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-01-17 10:27:58 -08:00
Tianon Gravi
af719275e9 Add test for IsCommitSHA function
Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2024-11-04 13:52:30 -08:00
Justin Chadwell
90d2d8b1c6 git: allow cloning commit shas not referenced by branch/tag
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-10-22 11:38:04 +01:00
Justin Chadwell
ac3eb58262 git: export gitutil helper for identifying commit shas
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-10-21 14:19:54 +01:00
Justin Chadwell
6493fd064c git: ensure exec option is propagated to child git clis
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-07-02 22:09:04 -07:00
Sebastiaan van Stijn
0f89a763aa vendor: github.com/containerd/containerd v1.7.18
Update to containerd 1.7.18, which now migrated to the errdefs module. The
existing errdefs package is now an alias for the module, and should no longer
be used directly.

This patch:

- updates the containerd dependency: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18
- replaces uses of the old package in favor of the new module
- adds a linter check to prevent accidental re-introduction of the old package
- adds a linter check to enforce using an alias, to prevent accidental use
  of the errdefs package in BuildKit or Moby.
- adds a linter check to prevent using the "log" package, which was also
  migrated to a separate module.

There are still some uses of the old package in (indirect) dependencies,
which should go away over time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 08:54:22 +02:00
Stephen Day
035832e0c9 gitutil: preserve error type when wrapping
Signed-off-by: Stephen Day <stephen.day@docker.com>
2024-05-21 16:34:28 -07:00
Justin Chadwell
8144ab88e7 git: restrict definition of git ref
During git refactoring, git refs accidentally became significantly
broader in definition - specifically, files like "foo.bar/test.git" - is
this a git repo at "foo.bar", or a local git directory?

We need to restrict this a lot more, previously, we only did this clever
conversion for the "github.com" prefix. This restores this previous
behavior.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-04-16 12:42:48 +01:00
Justin Chadwell
95ca25ec7d git: ensure file-looking git refs aren't parsed as URLs
URLs that look like `./path/to/file` and `../path/to/file` definitely
aren't git URLs - so we should bail out early.

This was causing a weird issue where if you copied `./.git` this would
be detected as a valid url parsing with `host = "."` and `path = "/git"`.
The fix for this is to make sure that for these explicit file-like
paths, we *never* parse them as url-refs.

Also some tests to make sure this doesn't break again!

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-18 15:21:10 +01:00
Justin Chadwell
3c6f6e4ee1 chore: refactor IsGitTransport to avoid duplication
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-02-01 15:39:16 +00:00
Justin Chadwell
9a51bb0ff1 git: use custom giturl type to preserve original remote
This resolves a regression introduced in
50e75e3565. In this previous patch, I'd
incorrectly assumed that scp-like URLs can express a subset of
"standard"-URLs and so we can always safely convert them for
consistency. This isn't true - the URL "git@example.com:foo" should be
resolved to the home directory of the host, however, the converted URL
"ssh://git@example.com/foo" will be resolved to the root of the host.

To resolve this, we need to not perform this conversion. However, we
also need preserve the behaviour of firm distinction between SCP and
normal URL types (so as to keep proper port parsing).

To do this, we add a new GitURL type to the gitutil package. This new
type contains all useful fields shared in common between the standard
libraries url package and our custom scp-style url parsing package. This
keeps the previous property of a single clean interface to all GitURLs,
while also ensuring that we preserve the original URL to pass to the Git
CLI (making sure we strip fragments out, which are used as
buildkit-level metadata).

As a side-effect of this, the client-side calling code for parsing
git urls is simplified (so we don't have to do fragment wrangling at
every call point).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-10-12 19:17:11 +01:00
Justin Chadwell
d34b2471cd git: centralize git cli operations
Move all of the git command line logic into a single object, inspired by
the object already in buildx.

The basic implemenation allows for configuring a git cli for a specific
repository, along with various authorization settings and custom
binaries. Commands can be run for that repository, and a few helpers are
provided for accessing data on it - more to come in the future
hopefully.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-24 12:22:15 +01:00
Justin Chadwell
a8d926a0c7 git: avoid regexp for checking .git suffix
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
Justin Chadwell
50e75e3565 git: update parsing to clarify between scp-style urls
This should also resolve the ports parsing issue.

Co-authored-by: Aaron Lehmann <alehmann@netflix.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
Justin Chadwell
e84cc9ea4f tests: tidy up gitutil testing structs
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-22 11:36:35 +01:00
CrazyMax
6a2287eddc fix support for empty git ref with subdir
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-02-08 12:21:43 +01:00
CrazyMax
b5c9183595 gitutil: use subtests
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2023-02-08 12:21:43 +01:00
CrazyMax
4a15e742d8 update golangci-lint to 1.48.0 (go 1.19 support) and fix linting issues
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-08-19 10:26:52 +02:00
Akihiro Suda
8bfeafaaa1 dockerfile (labs): implement ADD <git ref>
e.g.,

  # syntax=docker/dockerfile-upstream:master-labs
  FROM alpine
  ADD https://github.com/moby/buildkit.git#v0.10.1 /buildkit

Close issue 775

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-08-02 16:44:31 +09:00
Alex Couture-Beil
ca151bceaf Move git protocol detection into seperate util
- the git protocol detection is required by buildx, and should reside in
a seperate exported gitutil package.

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2021-03-31 12:42:57 -07:00