# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *


class GitLfs(MakefilePackage):
    """Git LFS is a system for managing and versioning large files in
       association with a Git repository.  Instead of storing the large files
       within the Git repository as blobs, Git LFS stores special "pointer
       files" in the repository, while storing the actual file contents on a
       Git LFS server."""

    homepage = "https://git-lfs.github.com"
    url      = "https://github.com/git-lfs/git-lfs/archive/v2.6.1.tar.gz"

    version('2.7.0', sha256='1c829ddd163be2206a44edb366bd7f6d84c5afae3496687405ca9d2a5f3af07b')
    version('2.6.1', sha256='e17cd9d4e66d1116be32f7ddc7e660c7f8fabbf510bc01b01ec15a22dd934ead')

    depends_on('go@1.5:', type='build')
    depends_on('git@1.8.2:', type='run')

    parallel = False

    # Git-lfs does not provide an 'install' target in the Makefile
    def install(self, spec, prefix):
        mkdirp(prefix.bin)
        install(join_path('bin', 'git-lfs'), prefix.bin)

var/spack/repos/builtin/packages/git-lfs/package.py
# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *


class GitLfs(MakefilePackage):
    """Git LFS is a system for managing and versioning large files in
       association with a Git repository.  Instead of storing the large files
       within the Git repository as blobs, Git LFS stores special "pointer
       files" in the repository, while storing the actual file contents on a
       Git LFS server."""

    homepage = "https://git-lfs.github.com"
    url      = "https://github.com/git-lfs/git-lfs/archive/v2.6.1.tar.gz"

    version('2.7.0', sha256='1c829ddd163be2206a44edb366bd7f6d84c5afae3496687405ca9d2a5f3af07b')
    version('2.6.1', sha256='e17cd9d4e66d1116be32f7ddc7e660c7f8fabbf510bc01b01ec15a22dd934ead')

    depends_on('go@1.5:', type='build')
    depends_on('git@1.8.2:', type='run')

    patch('patches/issue-10702.patch', when='@2.7.0')

    parallel = False

    # Git-lfs does not provide an 'install' target in the Makefile
    def install(self, spec, prefix):
        mkdirp(prefix.bin)
        install(join_path('bin', 'git-lfs'), prefix.bin)

var/spack/repos/builtin/packages/git-lfs/package.py
diff --git a/var/spack/repos/builtin/packages/git-lfs/package.py b/var/spack/repos/builtin/packages/git-lfs/package.py
index b6c4020dd3f147..98b52fba0c0704 100644
--- a/var/spack/repos/builtin/packages/git-lfs/package.py
+++ b/var/spack/repos/builtin/packages/git-lfs/package.py
@@ -22,6 +22,8 @@ class GitLfs(MakefilePackage):
     depends_on('go@1.5:', type='build')
     depends_on('git@1.8.2:', type='run')
 
+    patch('patches/issue-10702.patch', when='@2.7.0')
+
     parallel = False
 
     # Git-lfs does not provide an 'install' target in the Makefile
diff --git a/var/spack/repos/builtin/packages/git-lfs/patches/issue-10702.patch b/var/spack/repos/builtin/packages/git-lfs/patches/issue-10702.patch
new file mode 100644
index 00000000000000..aad2fe5a047ef2
--- /dev/null
+++ b/var/spack/repos/builtin/packages/git-lfs/patches/issue-10702.patch
@@ -0,0 +1,12 @@
+--- git-lfs-2.7.0/Makefile	2019-02-15 09:46:44.000000000 -0800
++++ git-lfs-2.7.0_patched/Makefile	2019-02-25 15:29:41.000000000 -0800
+@@ -29,7 +29,9 @@
+ endif
+ # EXTRA_LD_FLAGS are given by the caller, and are passed to the Go linker after
+ # BUILTIN_LD_FLAGS are processed. By default the system LDFLAGS are passed.
++ifdef LDFLAGS
+ EXTRA_LD_FLAGS ?= -extldflags ${LDFLAGS}
++endif
+ # LD_FLAGS is the union of the above two BUILTIN_LD_FLAGS and EXTRA_LD_FLAGS.
+ LD_FLAGS = $(BUILTIN_LD_FLAGS) $(EXTRA_LD_FLAGS)
+ 

git-lfs aborts (sometimes), fix in progress upstream
This is mostly an FYI.

Starting with `git-lfs@2.7.0` we frequently had `git-lfs` aborting.  In some situations it ran successfully, in others it didn't.  It seemed to depend on what other modules were loaded, but...

Between `git-lfs@2.6.1` and `git-lfs@2.7.0` the Makefile started unconditionally adding a `-extldflags` bit to the `go` command line, setting it to the value of `LDFLAGS`.  If `LDFLAGS` isn't set to anything (our case) then it wasn't given an argument, even though it needs one.  I'm not sure why this doesn't provide an error from the compiler, it seems to be grabbing something out of whatever comes next in memory.

I've changed the Makefile only set `-extldflags` if `LDFLAGS` is defined and made a Pull Request upstream:  https://github.com/git-lfs/git-lfs/pull/3545

Depending what Upstream has to say, perhaps we'll want to patch `git-lfs@2.7.0`, or forbid it, or ...

I'll keep this updated as the `git-lfs` PR progresses.


