Commit c7982d11 authored by Steve Azzopardi's avatar Steve Azzopardi

Fix git lfs not getting submodule objects

closes gitlab-org/gitlab-runner#4123
parent d9b83537
......@@ -32,6 +32,10 @@ const (
repoLFSBeforeSHA = "91956efe32fb7bef54f378d90c9bd74c19025872"
repoLFSRefName = "add-lfs-object"
repoSubmoduleLFSSHA = "d0cb7ff49b5c4fcf159e860fd6b30ef40731c435"
repoSubmoduleLFSBeforeSHA = "dcbc4f0c93cb1731eeac4e3a70a55a991838e137"
repoSubmoduleLFSRefName = "add-lfs-submodule"
FilesLFSFile1LFSsize = int64(2097152)
)
......@@ -66,6 +70,17 @@ func GetLFSGitInfo(url string) GitInfo {
}
}
func GetSubmoduleLFSGitInfo(url string) GitInfo {
return GitInfo{
RepoURL: url,
Sha: repoSubmoduleLFSSHA,
BeforeSha: repoSubmoduleLFSBeforeSHA,
Ref: repoSubmoduleLFSRefName,
RefType: repoRefType,
Refspecs: []string{"+refs/heads/*:refs/origin/heads/*", "+refs/tags/*:refs/tags/*"},
}
}
func GetSuccessfulBuild() (JobResponse, error) {
return GetLocalBuildResponse("echo Hello World")
}
......
......@@ -567,6 +567,51 @@ func TestBuildWithGitStrategyCloneNoCheckoutWithLFS(t *testing.T) {
})
}
func TestBuildWithSubmoduleLFSPullsLFSObject(t *testing.T) {
skipIfGitDoesNotSupportLFS(t)
shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
assert.NoError(t, err)
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "normal"})
build.GitInfo = common.GetSubmoduleLFSGitInfo(build.GitInfo.RepoURL)
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository")
f, err := os.Stat(filepath.Join(build.FullProjectDir(), "lfs", "1.lfs"))
require.NoError(t, err)
assert.Equal(t, common.FilesLFSFile1LFSsize, f.Size())
})
}
func TestBuildWithSubmoduleLFSDisabledSmudging(t *testing.T) {
skipIfGitDoesNotSupportLFS(t)
shellstest.OnEachShell(t, func(t *testing.T, shell string) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
assert.NoError(t, err)
build, cleanup := newBuild(t, successfulBuild, shell)
defer cleanup()
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_STRATEGY", Value: "fetch"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_SUBMODULE_STRATEGY", Value: "normal"})
build.Variables = append(build.Variables, common.JobVariable{Key: "GIT_LFS_SKIP_SMUDGE", Value: "1", Public: true})
build.GitInfo = common.GetSubmoduleLFSGitInfo(build.GitInfo.RepoURL)
out, err := runBuildReturningOutput(t, build)
assert.NoError(t, err)
assert.Contains(t, out, "Created fresh repository")
f, err := os.Stat(filepath.Join(build.FullProjectDir(), "lfs", "1.lfs"))
require.NoError(t, err)
assert.True(t, f.Size() < common.FilesLFSFile1LFSsize)
})
}
func TestBuildWithGitSubmoduleStrategyNone(t *testing.T) {
for _, strategy := range []string{"none", ""} {
t.Run("strategy "+strategy, func(t *testing.T) {
......
......@@ -222,6 +222,12 @@ func (b *AbstractShell) writeSubmoduleUpdateCmd(w ShellWriter, build *common.Bui
w.Command("git", append(foreachArgs, "git", "clean", "-ffxd")...)
w.Command("git", append(foreachArgs, "git", "reset", "--hard")...)
w.Command("git", updateArgs...)
if !build.IsLFSSmudgeDisabled() {
w.IfCmd("git-lfs", "version")
w.Command("git", append(foreachArgs, "git", "lfs", "pull")...)
w.EndIf()
}
}
func (b *AbstractShell) cacheFile(build *common.Build, userKey string) (key, file string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment