File size: 1,350 Bytes
659ff9d
 
 
 
 
27c67cd
 
 
659ff9d
 
 
 
 
 
 
 
 
27c67cd
 
 
659ff9d
 
27c67cd
 
 
 
 
 
 
 
 
659ff9d
 
 
 
 
 
 
 
 
 
 
 
 
 
27c67cd
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

# Set the directory to search for files (current directory by default)
TARGET_DIR=${1:-.}

# Set the size threshold for using Git LFS (in bytes, e.g., 10MB)
LFS_THRESHOLD=$((10 * 1024 * 1024)) # 10MB

# Check if the directory exists
if [ ! -d "$TARGET_DIR" ]; then
    echo "Directory $TARGET_DIR does not exist."
    exit 1
fi

# Navigate to the target directory
cd "$TARGET_DIR" || exit

# Ensure Git LFS is initialized
git lfs install --skip-smudge

# Find all files recursively
find . -type f | while read -r file; do
    # Get the file size in bytes
    FILE_SIZE=$(stat --format=%s "$file")

    if [ "$FILE_SIZE" -ge "$LFS_THRESHOLD" ]; then
        # Track the file with Git LFS
        git lfs track "$file"
        echo "Tracked large file with LFS: $file"
    fi

    # Add the file to the Git staging area
    git add "$file"

    # Commit the file with a message, ignoring empty commits
    git commit -m "Added file $file" || {
        echo "Skipped empty commit for $file"
        continue
    }

    # Push the commit to the remote repository
    git push

    echo "Processed $file"
done

# Commit and push the updated .gitattributes file (if any)
if git diff --cached --name-only | grep -q '.gitattributes'; then
    git commit -m "Updated .gitattributes for LFS" || echo "No changes to .gitattributes"
    git push
fi