Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/git-lfs/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "git-lfs",
"version": "1.2.5",
"version": "1.2.6",
"name": "Git Large File Support (LFS)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/git-lfs",
"description": "Installs Git Large File Support (Git LFS) along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like git and curl.",
Expand Down
11 changes: 9 additions & 2 deletions src/git-lfs/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,18 @@ if [ "${AUTO_PULL}" != "true" ]; then
exit 0
fi

# Check if repo is a git lfs repo.
if ! git lfs ls-files > /dev/null 2>&1; then
# Check if repo is a git lfs enabled repo by running 'git lfs ls-files'
if ! ls_files_output=$(git lfs ls-files 2>&1); then
echo "(!) Skipping automatic 'git lfs pull' because 'git lfs ls-files' failed"
exit 0
fi

# Check if 'git lfs ls-files' output is empty
if [ -z "$ls_files_output" ]; then
echo "(!) Skipping automatic 'git lfs pull' because no git lfs files were detected"
exit 0
fi

git lfs install
git lfs pull
EOF
Expand Down
35 changes: 35 additions & 0 deletions test/git-lfs/noLfsFiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

# Test for git-lfs behavior with repos that have no LFS files
# This tests the fix for the issue where git lfs install was running unnecessarily

# Optional: Import test library
source dev-container-features-test-lib

# Test that git-lfs is installed
check "git-lfs version" git-lfs --version

# Test the generated script exists
check "pull script exists" test -f /usr/local/share/pull-git-lfs-artifacts.sh

# We should already be in a git repository created by initializeCommand
# Verify we're in a git repository
check "in git repository" git rev-parse --is-inside-work-tree

# Test that git lfs ls-files returns empty output
check "git lfs ls-files returns empty output" test -z "$(git lfs ls-files 2>/dev/null)"

# Verify no LFS hooks exist initially (the script should have already run during postCreateCommand)
HOOKS_COUNT=$(find .git/hooks -type f ! -name '*.sample' | wc -l)
check "no git hooks installed after postCreateCommand" test "$HOOKS_COUNT" -eq 0

# Double check: specifically look for the hooks that git lfs install would create
check "no post-merge hook" test ! -f .git/hooks/post-merge
check "no pre-push hook" test ! -f .git/hooks/pre-push
check "no post-commit hook" test ! -f .git/hooks/post-commit
check "no post-checkout hook" test ! -f .git/hooks/post-checkout

# Report results
reportResults
8 changes: 8 additions & 0 deletions test/git-lfs/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
}
}
},
"noLfsFiles": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"initializeCommand": "git init && git config user.email '[email protected]' && git config user.name 'Test User' && echo 'regular file content' > regular.txt && git add regular.txt && git commit -m 'Initial commit without LFS'",
"remoteUser": "vscode",
"features": {
"git-lfs": {}
}
},
"use_github": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"remoteUser": "vscode",
Expand Down