git-lfs-advisor-cli 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: git-lfs-advisor-cli
3
+ Version: 0.1.0
4
+ Summary: A script to find large/binary files and generate Git LFS commands.
5
+ Home-page: https://github.com/taicaile/git-lfs-advisor
6
+ Author: taicaile
7
+ Author-email:
8
+ Project-URL: Bug Tracker, https://github.com/taicaile/git-lfs-advisor/issues
9
+ Project-URL: Source Code, https://github.com/taicaile/git-lfs-advisor
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Environment :: Console
14
+ Classifier: Topic :: Software Development :: Version Control :: Git
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ Dynamic: author
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: project-url
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ # Git LFS Advisor
27
+
28
+ A simple command-line tool to scan a Git repository, find files suitable for Git LFS, and generate the necessary configuration commands.
29
+
30
+ This tool helps you quickly set up Git LFS for a new or existing project without manually checking every file.
31
+
32
+ ## ✨ Features
33
+
34
+ - **Repository Scan**: Scans the entire Git repository to find large or binary files.
35
+ - **Custom Rules**: Define scanning rules based on file size or file extension.
36
+ - **Command Generation**: Automatically generates `git lfs track` and `git lfs migrate` commands for you to copy and execute.
37
+ - **Cross-Platform**: Built with Python, it runs on Windows, macOS, and Linux.
38
+
39
+ ## 📋 What It Does
40
+
41
+ 1. **Scans** your repository for large files and binary assets
42
+ 2. **Analyzes** file patterns, sizes, and repository structure
43
+ 3. **Recommends** which files should be tracked by Git LFS
44
+ 4. **Generates** `.gitattributes` configuration automatically
45
+ 5. **Provides** migration commands and best practices
46
+
47
+ ## 🎯 Use Cases
48
+
49
+ - Setting up LFS for new repositories
50
+ - Optimizing existing repositories with large files
51
+ - Migrating from regular Git to Git LFS
52
+ - Repository cleanup and size optimization
53
+ - CI/CD pipeline integration
54
+
55
+ ## 📊 Example Output
56
+
57
+ ```txt
58
+ 🔍 Scanning repository...
59
+ 📁 Found 1,247 files (Total: 2.3 GB)
60
+
61
+ 💡 LFS Recommendations:
62
+ • *.psd files (127 files, 890 MB) → Track with LFS
63
+ • *.mp4 files (23 files, 1.2 GB) → Track with LFS
64
+ • *.zip files (8 files, 156 MB) → Track with LFS
65
+
66
+ 📝 Generated .gitattributes:
67
+ *.psd filter=lfs diff=lfs merge=lfs -text
68
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
69
+ *.zip filter=lfs diff=lfs merge=lfs -text
70
+
71
+ 💾 Potential space savings: ~2.1 GB in Git history
72
+ ```
73
+
74
+ ## 🛠️ Installation
75
+
76
+ ```bash
77
+ pip install git-lfs-advisor-cli
78
+ ```
79
+
80
+ ## 🤝 Contributing
81
+
82
+ Contributions are welcome!
83
+
84
+ ## ⭐ Show Your Support
85
+
86
+ If this tool helps you manage your Git LFS setup, please give it a star! ⭐
87
+
88
+ ---
89
+
90
+ **Made with ❤️ for better Git workflows**
@@ -0,0 +1,65 @@
1
+ # Git LFS Advisor
2
+
3
+ A simple command-line tool to scan a Git repository, find files suitable for Git LFS, and generate the necessary configuration commands.
4
+
5
+ This tool helps you quickly set up Git LFS for a new or existing project without manually checking every file.
6
+
7
+ ## ✨ Features
8
+
9
+ - **Repository Scan**: Scans the entire Git repository to find large or binary files.
10
+ - **Custom Rules**: Define scanning rules based on file size or file extension.
11
+ - **Command Generation**: Automatically generates `git lfs track` and `git lfs migrate` commands for you to copy and execute.
12
+ - **Cross-Platform**: Built with Python, it runs on Windows, macOS, and Linux.
13
+
14
+ ## 📋 What It Does
15
+
16
+ 1. **Scans** your repository for large files and binary assets
17
+ 2. **Analyzes** file patterns, sizes, and repository structure
18
+ 3. **Recommends** which files should be tracked by Git LFS
19
+ 4. **Generates** `.gitattributes` configuration automatically
20
+ 5. **Provides** migration commands and best practices
21
+
22
+ ## 🎯 Use Cases
23
+
24
+ - Setting up LFS for new repositories
25
+ - Optimizing existing repositories with large files
26
+ - Migrating from regular Git to Git LFS
27
+ - Repository cleanup and size optimization
28
+ - CI/CD pipeline integration
29
+
30
+ ## 📊 Example Output
31
+
32
+ ```txt
33
+ 🔍 Scanning repository...
34
+ 📁 Found 1,247 files (Total: 2.3 GB)
35
+
36
+ 💡 LFS Recommendations:
37
+ • *.psd files (127 files, 890 MB) → Track with LFS
38
+ • *.mp4 files (23 files, 1.2 GB) → Track with LFS
39
+ • *.zip files (8 files, 156 MB) → Track with LFS
40
+
41
+ 📝 Generated .gitattributes:
42
+ *.psd filter=lfs diff=lfs merge=lfs -text
43
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
44
+ *.zip filter=lfs diff=lfs merge=lfs -text
45
+
46
+ 💾 Potential space savings: ~2.1 GB in Git history
47
+ ```
48
+
49
+ ## 🛠️ Installation
50
+
51
+ ```bash
52
+ pip install git-lfs-advisor-cli
53
+ ```
54
+
55
+ ## 🤝 Contributing
56
+
57
+ Contributions are welcome!
58
+
59
+ ## ⭐ Show Your Support
60
+
61
+ If this tool helps you manage your Git LFS setup, please give it a star! ⭐
62
+
63
+ ---
64
+
65
+ **Made with ❤️ for better Git workflows**
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,46 @@
1
+ import setuptools
2
+
3
+ # Read the contents of your README file
4
+ from pathlib import Path
5
+ this_directory = Path(__file__).parent
6
+ long_description = (this_directory / "README.md").read_text(encoding="utf-8")
7
+
8
+ setuptools.setup(
9
+ name="git-lfs-advisor-cli",
10
+ version="0.1.0",
11
+ author="taicaile",
12
+ author_email="",
13
+ # A short, one-sentence summary of the package
14
+ description="A script to find large/binary files and generate Git LFS commands.",
15
+ # A long description read from the README.md file
16
+ long_description=long_description,
17
+ long_description_content_type='text/markdown', # Important for rendering on PyPI
18
+ url="https://github.com/taicaile/git-lfs-advisor", # Replace with your project's URL
19
+ # Use a standard src layout to find the package
20
+ package_dir={'': 'src'},
21
+ packages=setuptools.find_packages(where='src'),
22
+ classifiers=[
23
+ "Programming Language :: Python :: 3",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Operating System :: OS Independent",
26
+ "Environment :: Console",
27
+ "Topic :: Software Development :: Version Control :: Git",
28
+ ],
29
+ python_requires='>=3.6',
30
+ # List of dependencies required by your package
31
+ install_requires=[
32
+ # e.g., 'requests>=2.20.0',
33
+ ],
34
+ project_urls={
35
+ "Bug Tracker": "https://github.com/taicaile/git-lfs-advisor/issues",
36
+ "Source Code": "https://github.com/taicaile/git-lfs-advisor",
37
+ },
38
+ # Define the command-line entry point
39
+ entry_points={
40
+ 'console_scripts': [
41
+ # This creates a command 'git-lfs-advisor' that executes the main() function
42
+ # in the 'cli.py' module within our 'get_lfs_advisor_cli' package.
43
+ 'git-lfs-advisor=get_lfs_advisor_cli.cli:main',
44
+ ],
45
+ },
46
+ )
@@ -0,0 +1,162 @@
1
+ import os
2
+ import sys
3
+ import configparser
4
+ import pathlib
5
+
6
+ # --- Configuration ---
7
+ SIZE_LIMIT_MB = 25
8
+ # A set of common binary file extensions. Add more as needed for your project.
9
+ BINARY_EXTENSIONS = {
10
+ # Images
11
+ '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.ico', '.svg',
12
+ # Documents
13
+ '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx',
14
+ # Archives
15
+ '.zip', '.rar', '.7z', '.gz', '.tar',
16
+ # Compiled code and libraries
17
+ '.exe', '.dll', '.so', '.a', '.lib',
18
+ # Media
19
+ '.mp3', '.wav', '.ogg', '.mp4', '.mov', '.avi',
20
+ # Databases
21
+ '.db', '.sqlite', '.sqlite3',
22
+ # Other
23
+ '.jar', '.bin', '.dat',
24
+ }
25
+ # --- End Configuration ---
26
+
27
+
28
+ SIZE_LIMIT_BYTES = SIZE_LIMIT_MB * 1024 * 1024
29
+
30
+
31
+ def is_binary_file(filepath, chunk_size=1024):
32
+ """
33
+ Heuristically determines if a file is binary by checking for null bytes
34
+ in the first chunk of the file.
35
+ """
36
+ try:
37
+ with open(filepath, 'rb') as f:
38
+ return b'\0' in f.read(chunk_size)
39
+ except IOError:
40
+ return False # Could not read, assume not binary for safety.
41
+
42
+
43
+ def get_submodule_paths():
44
+ """Parses .gitmodules and returns a set of submodule paths."""
45
+ submodules = set()
46
+ gitmodules_path = '.gitmodules'
47
+ if not os.path.exists(gitmodules_path):
48
+ return submodules
49
+
50
+ print("Found .gitmodules, parsing for submodule paths...")
51
+ config = configparser.ConfigParser()
52
+ try:
53
+ config.read(gitmodules_path)
54
+ for section in config.sections():
55
+ if config.has_option(section, 'path'):
56
+ path_str = config.get(section, 'path')
57
+ # Normalize path for the current OS (e.g., using '\' on Windows)
58
+ normalized_path = str(pathlib.Path(path_str))
59
+ submodules.add(normalized_path)
60
+ except configparser.Error as e:
61
+ print(f"Warning: Could not parse .gitmodules file: {e}", file=sys.stderr)
62
+
63
+ if submodules:
64
+ print("The following submodule paths will be ignored:")
65
+ for path in sorted(list(submodules)):
66
+ print(f" - {path}")
67
+ return submodules
68
+
69
+
70
+ def scan_repo_files(submodule_paths):
71
+ """Walks the repo, yielding file paths to be analyzed."""
72
+ for root, dirs, files in os.walk('.', topdown=True):
73
+ if '.git' in dirs:
74
+ dirs.remove('.git')
75
+
76
+ for d in dirs[:]:
77
+ dir_path = str(pathlib.Path(root) / d)
78
+ if dir_path in submodule_paths:
79
+ print(f"Ignoring submodule directory: '{dir_path}'")
80
+ dirs.remove(d)
81
+
82
+ for filename in files:
83
+ yield os.path.join(root, filename)
84
+
85
+
86
+ def analyze_file(file_path):
87
+ """Analyzes a single file and returns an LFS pattern if it matches criteria."""
88
+ try:
89
+ normalized_path = str(pathlib.Path(file_path).as_posix())
90
+ file_size = os.path.getsize(file_path)
91
+ is_large = file_size > SIZE_LIMIT_BYTES
92
+ is_bin = False
93
+
94
+ if not is_large:
95
+ _, ext = os.path.splitext(file_path)
96
+ if ext.lower() in BINARY_EXTENSIONS:
97
+ is_bin = True
98
+ else:
99
+ is_bin = is_binary_file(file_path)
100
+
101
+ if is_large or is_bin:
102
+ if is_large:
103
+ size_in_mb = file_size / (1024 * 1024)
104
+ print(f"Found large file: '{normalized_path}' (Size: {size_in_mb:.2f}MB)")
105
+ else:
106
+ print(f"Found binary file: '{normalized_path}' (Reason: Binary content)")
107
+
108
+ if '.' in os.path.basename(file_path):
109
+ _, ext = os.path.splitext(file_path)
110
+ return f"*{ext.lower()}"
111
+ else:
112
+ return normalized_path
113
+
114
+ except FileNotFoundError:
115
+ print(f"Warning: Could not access '{file_path}'. Skipping.", file=sys.stderr)
116
+
117
+ return None
118
+
119
+
120
+ def print_lfs_suggestions(lfs_patterns):
121
+ """Prints the suggested LFS commands based on found patterns."""
122
+ if not lfs_patterns:
123
+ print(f"No files found exceeding {SIZE_LIMIT_MB}MB or detected as binary.")
124
+ return
125
+
126
+ print("\n--- Suggested git lfs track commands (for .gitattributes) ---")
127
+ print("# Run these commands to update your .gitattributes file.")
128
+ sorted_patterns = sorted(list(lfs_patterns))
129
+ for pattern in sorted_patterns:
130
+ print(f'git lfs track "{pattern}"')
131
+
132
+ print("\n--- Suggested git lfs migrate command (for rewriting history) ---")
133
+ include_arg = ",".join(sorted_patterns)
134
+ print("\n# WARNING: The following commands rewrite the history of your repository.")
135
+ print("# It is STRONGLY RECOMMENDED to run this on a fresh clone or to backup your repository first.")
136
+ print("\n# --- Option 1: Migrate ONLY the CURRENT branch (most common) ---")
137
+ print(f'git lfs migrate import --include="{include_arg}"')
138
+ print("\n# --- Option 2: Migrate a SPECIFIC branch (e.g., 'main') ---")
139
+ print(f'# git lfs migrate import --include="{include_arg}" main')
140
+ print("\n# --- Option 3: Migrate ALL local and remote branches ---")
141
+ print(f'# git lfs migrate import --include="{include_arg}" --everything')
142
+
143
+
144
+ def main():
145
+ """Finds large or binary files and generates .gitattributes LFS rules."""
146
+ print(f"Scanning for files larger than {SIZE_LIMIT_MB}MB or binary files...")
147
+ submodule_paths = get_submodule_paths()
148
+ print("----------------------------------------")
149
+
150
+ lfs_patterns = set()
151
+ for file_path in scan_repo_files(submodule_paths):
152
+ pattern = analyze_file(file_path)
153
+ if pattern:
154
+ lfs_patterns.add(pattern)
155
+
156
+ print("----------------------------------------")
157
+ print("Scan complete.")
158
+ print_lfs_suggestions(lfs_patterns)
159
+
160
+
161
+ if __name__ == "__main__":
162
+ main()
@@ -0,0 +1,90 @@
1
+ Metadata-Version: 2.4
2
+ Name: git-lfs-advisor-cli
3
+ Version: 0.1.0
4
+ Summary: A script to find large/binary files and generate Git LFS commands.
5
+ Home-page: https://github.com/taicaile/git-lfs-advisor
6
+ Author: taicaile
7
+ Author-email:
8
+ Project-URL: Bug Tracker, https://github.com/taicaile/git-lfs-advisor/issues
9
+ Project-URL: Source Code, https://github.com/taicaile/git-lfs-advisor
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Environment :: Console
14
+ Classifier: Topic :: Software Development :: Version Control :: Git
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ Dynamic: author
18
+ Dynamic: classifier
19
+ Dynamic: description
20
+ Dynamic: description-content-type
21
+ Dynamic: home-page
22
+ Dynamic: project-url
23
+ Dynamic: requires-python
24
+ Dynamic: summary
25
+
26
+ # Git LFS Advisor
27
+
28
+ A simple command-line tool to scan a Git repository, find files suitable for Git LFS, and generate the necessary configuration commands.
29
+
30
+ This tool helps you quickly set up Git LFS for a new or existing project without manually checking every file.
31
+
32
+ ## ✨ Features
33
+
34
+ - **Repository Scan**: Scans the entire Git repository to find large or binary files.
35
+ - **Custom Rules**: Define scanning rules based on file size or file extension.
36
+ - **Command Generation**: Automatically generates `git lfs track` and `git lfs migrate` commands for you to copy and execute.
37
+ - **Cross-Platform**: Built with Python, it runs on Windows, macOS, and Linux.
38
+
39
+ ## 📋 What It Does
40
+
41
+ 1. **Scans** your repository for large files and binary assets
42
+ 2. **Analyzes** file patterns, sizes, and repository structure
43
+ 3. **Recommends** which files should be tracked by Git LFS
44
+ 4. **Generates** `.gitattributes` configuration automatically
45
+ 5. **Provides** migration commands and best practices
46
+
47
+ ## 🎯 Use Cases
48
+
49
+ - Setting up LFS for new repositories
50
+ - Optimizing existing repositories with large files
51
+ - Migrating from regular Git to Git LFS
52
+ - Repository cleanup and size optimization
53
+ - CI/CD pipeline integration
54
+
55
+ ## 📊 Example Output
56
+
57
+ ```txt
58
+ 🔍 Scanning repository...
59
+ 📁 Found 1,247 files (Total: 2.3 GB)
60
+
61
+ 💡 LFS Recommendations:
62
+ • *.psd files (127 files, 890 MB) → Track with LFS
63
+ • *.mp4 files (23 files, 1.2 GB) → Track with LFS
64
+ • *.zip files (8 files, 156 MB) → Track with LFS
65
+
66
+ 📝 Generated .gitattributes:
67
+ *.psd filter=lfs diff=lfs merge=lfs -text
68
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
69
+ *.zip filter=lfs diff=lfs merge=lfs -text
70
+
71
+ 💾 Potential space savings: ~2.1 GB in Git history
72
+ ```
73
+
74
+ ## 🛠️ Installation
75
+
76
+ ```bash
77
+ pip install git-lfs-advisor-cli
78
+ ```
79
+
80
+ ## 🤝 Contributing
81
+
82
+ Contributions are welcome!
83
+
84
+ ## ⭐ Show Your Support
85
+
86
+ If this tool helps you manage your Git LFS setup, please give it a star! ⭐
87
+
88
+ ---
89
+
90
+ **Made with ❤️ for better Git workflows**
@@ -0,0 +1,9 @@
1
+ README.md
2
+ setup.py
3
+ src/get_lfs_advisor_cli/__init__.py
4
+ src/get_lfs_advisor_cli/cli.py
5
+ src/git_lfs_advisor_cli.egg-info/PKG-INFO
6
+ src/git_lfs_advisor_cli.egg-info/SOURCES.txt
7
+ src/git_lfs_advisor_cli.egg-info/dependency_links.txt
8
+ src/git_lfs_advisor_cli.egg-info/entry_points.txt
9
+ src/git_lfs_advisor_cli.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ git-lfs-advisor = get_lfs_advisor_cli.cli:main
@@ -0,0 +1 @@
1
+ get_lfs_advisor_cli