Commit Graph

32 Commits (master)

Author SHA1 Message Date
Michael Gratton 068a598025 Ensure shallow repo mirror is updated when the git ref changes
Shallow clones only contain the ref that was cloned, and so if a
mirror is shallow and the ref is changed in a subsequent invocation of
builder, the new ref is absent and git fails with an error.

This patch avoids bailing out too soon when mirroring a repo if the
requested ref does not exist, to ensure it is fetched.

Fixes #285

Closes: #286
Approved by: alexlarsson
2019-05-14 10:56:23 +00:00
Mathieu Bridon 416b7f599b Remove builder_git_checkout_dir
It is completely unused now that we checkout the whole tree in the
from-git code path.

Closes: #260
Approved by: alexlarsson
2019-02-05 14:58:27 +00:00
Alexander Larsson 099bb87b77 git: Look for the correct cache
When cloning a new repo the mirror_dir has a temporary basename, so
use real_mirror_dir when looking for the cached repo.
2018-02-16 11:39:09 +01:00
Alexander Larsson 63e0722cb0 git: When mirroring a new repo, use a temporary destination
This way, if anything fails during the initial pull we can remove it
and not be confused by a partial repo on the next run.

Closes: #98
Approved by: alexlarsson
2018-01-11 09:30:42 +00:00
Alexander Larsson cd0c9da8f3 Fix --disable-updates for git sources
We lost the ability to not update if a git repo was already checked out.
This fixes that again.

Closes: #98
Approved by: alexlarsson
2018-01-11 09:30:42 +00:00
Philip Withnall 4e4a7c9af5 git: Print details of ignored error when mirroring
Rather than dropping the error on the floor entirely.

Coverity CID: #208384

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #74
Approved by: alexlarsson
2017-12-06 09:23:17 +00:00
Alexander Larsson a177961181 git: pass -f to git fetch
This means we handle non-fastforwarded branches
2017-11-07 10:21:02 +01:00
Alexander Larsson e7287852ad git: Support HEAD as ref when mirroring a repo
This is useful to reference whatever is currently checked out in a local
repo.
2017-11-06 14:27:25 +01:00
Alexander Larsson 784328e397 git: Always deep clone for old git versions if bundling sources
If we're bundling sources we really need to fetch from them because
we want to bundle shallow clones. However, this doesn't work for older
git versions, so pre-emptively fetch those deeply.

Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson 25805d5220 git: Add git mirror flags to simplify API
This is nicer than a bunch of booleans

Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson 020461583a git: Add helper for checking for shallow clone
Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson 55f07e209a git: Disable shallow clones of submodules pre git 1.9.0
Fetching from shallow clones was added in 1.9.0, so we do deep
clones of submodule repos before that to ensure submodule update
works.

Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson 3d603320f2 git: Add helper for checking git version for feature
Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson baf8d4630b git: Explicitly pull all refs when doing full pull
Older versions of git default to only tags when you do --tags instead
of tags + all. So, we force everything with --tags *:*.

Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson 3afbb5a6d2 Fix bundling of git sources specifying a tag object
When pulling the commit we need to also pull the tags so we have them
locally, and then we need to peel the ref when we commit it so that we
don't try to create a ref pointing to a non-commit (tag) object.

Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson c5cd6f50f6 Fix crashes on git errors
We returned FALSE but error was unset, leading to a crash printing
the error message.

Closes: #62
Approved by: alexlarsson
2017-11-06 12:42:36 +00:00
Alexander Larsson 4c0b9ae0e3 git: Use cp -al instead of git clone when checking out git mirror
This fixes older versions of git not supporting clones from shallow
repos.
2017-10-31 11:22:44 +01:00
Alexander Larsson 7d532f5125 git: Disable fsck when doing shallow clones on git < 1.8.3.2
The git 1.8.3.2 release notes say:

 * Cloning with "git clone --depth N" while fetch.fsckobjects (or
   transfer.fsckobjects) is set to true did not tell the cut-off
   points of the shallow history to the process that validates the
   objects and the history received, causing the validation to fail.

So, on versions prior to this, we always disable fsck when you're
pulling shallowly. If you need fsck validation, use a newer git.
2017-10-31 10:22:52 +01:00
Alexander Larsson bf7aeacded git: Don't clone refs that is not under refs/
HEAD gives all sorts of problems
2017-10-31 09:05:59 +01:00
Alexander Larsson a39f727adf git: Never do shallow pulls if we once had a deep one
This seems to break on old versions of git. For example:

$ git --version
git version 1.8.3.1
$ git clone --mirror https://github.com/divVerent/s2tc.git
Cloning into bare repository 's2tc.git'...
remote: Counting objects: 740, done.
remote: Total 740 (delta 0), reused 0 (delta 0), pack-reused 740
Receiving objects: 100% (740/740), 1.47 MiB | 0 bytes/s, done.
Resolving deltas: 100% (493/493), done.
$ cd s2tc.git/
$ git fetch -p --no-recurse-submodules --no-tags --depth=1 -f origin '+HEAD:HEAD'
fatal: git fetch-pack: expected shallow list

Closes: #55
Approved by: alexlarsson
2017-10-30 10:57:35 +00:00
Alexander Larsson 17f659ee71 git: --unshallow if we do a full pull where we were previously shallow
Closes: #55
Approved by: alexlarsson
2017-10-30 10:57:35 +00:00
Alexander Larsson ac6a25c981 Add option to disable shallow clone for git sources
Closes: #55
Approved by: alexlarsson
2017-10-30 10:57:35 +00:00
Alexander Larsson 7e124f0e91 Work around issues with older versions of git
It turns out older versions of git cannot properly check out a commit
if the ref that points to it was not a normal one (branch or tag).
So, we work around this case by detecting it add adding a fake
tag. Also, we change the fake ref we use for commit-only references
to be a regular branch and not a special one for the same reason.

This fixes https://github.com/flatpak/flatpak/issues/1133

Closes: #52
Approved by: alexlarsson
2017-10-27 10:41:20 +00:00
Alexander Larsson 15f3582e40 Fix checkout of shallow repo.
Some manifest (cx.ring.RingGnome) had a git commit id that
was only tip of a non-branch ref (refs/changes/51/8051/8), which
was not cloned by a regular clone, so we need to switch to
a clone --mirror.

Closes: #50
Approved by: alexlarsson
2017-10-19 20:39:08 +00:00
Alexander Larsson be8597f346 git: Try to do shallow mirrors when downloading
When downloading a git repo we try to do a shallow (depth=1) fetch of
only the specified target. This normally works fine for branches and
tags, but if the commit is a raw SHA1 then it fails, because we can
only request refs from the remote.

We handle this by doing an ls-remote and seeing if the specified
target is either a (possilby partial) ref, or a commit id that a
remote ref is pointing at. If it is, we pull that ref only. If not,
then we fall back to a full fetch.

I believe this is the best we can do to fix
 https://github.com/flatpak/flatpak-builder/issues/6

Closes: #47
Approved by: alexlarsson
2017-10-17 10:31:28 +00:00
Alexander Larsson 42da157c47 git: Create fake refs that are not branches when doing shallow mirrors
When doing a shallow clone when bundling git sources we sometimes need
to create a ref in the source repo. This changes the ref used from
refs/heads/flatpak-builder/ref-$REF to refs/flatpak/ref-$REF.
In other words, it uses a custom ref rather than a branch, which has
less chance of conflicting with some existing branch.

Closes: #47
Approved by: alexlarsson
2017-10-17 10:31:28 +00:00
Alexander Larsson 04cf19083e git: Add GSubprocessFlags to git()
Closes: #47
Approved by: alexlarsson
2017-10-17 10:31:28 +00:00
Alexander Larsson 039a24aeb4 utils: Add flags argument to flatpak_spawn
This allows you to e.g. silence STDERR

Closes: #47
Approved by: alexlarsson
2017-10-17 10:31:28 +00:00
Alexander Larsson 6294fafcc4 git: Fix problems bundling git repos on older git versions
It seems we have to specify

git fetch --depth 1 origin $ref:$ref

instead of

git fetch --depth 1 origin $ref

because on older versions of git (1.8.3 at least) this otherwise just
sets FETCH_HEAD, rather than $ref in the fetching repo.
2017-09-26 19:36:09 +02:00
Alexander Larsson 0e5fdaf89a bundle git repos shallowly
There is no need to bundle the entire history in a git repo.
Instead we only bundle shallow versions of all the branches/tags/commit
that we reference.

For directly specified commit ids we can't really shallow-clone those,
so we create fake tags in the mirrored repo.
2017-09-21 16:05:05 +02:00
Alexander Larsson faba587a72 Move common/flatpak-utils.* to src/builder-flatpak-utils.* 2017-08-25 09:36:49 +02:00
Alexander Larsson 5823533bd7 Move builder/ to src/ 2017-08-25 09:30:53 +02:00