This guide walks you through the process of installing Git AST and setting up your environment.
Before installing Git AST, ensure you have the following prerequisites:
- Git: Git AST is an extension to Git, so you need Git installed (version 2.28.0 or later recommended)
- Rust: The core tools are written in Rust (version 1.67.0 or later)
- Tree-sitter: Required for parsing source code files
- Language-specific formatters: For languages you plan to use with Git AST
We're working on providing package manager installation for common platforms. This will be available in the future.
-
Clone the repository:
git clone https://github.com/yourusername/git-ast.git cd git-ast -
Build the project:
cargo build --release
-
Add to your PATH:
# For Unix/Linux/macOS: export PATH="$PATH:$(pwd)/target/release" # Add to your shell profile for persistence echo 'export PATH="$PATH:$HOME/path/to/git-ast/target/release"' >> ~/.bashrc # or ~/.zshrc
After installing Git AST, you need to configure each repository where you want to use it:
-
Create
.gitattributesfile in your repository root:# Configure Git AST for specific file types *.rs filter=git-ast-rust *.js filter=git-ast-javascript # Add more file types as needed -
Configure Git filters:
# For Rust files git config --local filter.git-ast-rust.clean "git-ast clean --lang=rust" git config --local filter.git-ast-rust.smudge "git-ast smudge --lang=rust" git config --local filter.git-ast-rust.required true # For JavaScript files git config --local filter.git-ast-javascript.clean "git-ast clean --lang=javascript" git config --local filter.git-ast-javascript.smudge "git-ast smudge --lang=javascript" git config --local filter.git-ast-javascript.required true
For better performance, use Git's filter process protocol:
git config --local filter.git-ast-rust.process "git-ast filter-process --lang=rust"
git config --local filter.git-ast-javascript.process "git-ast filter-process --lang=javascript"To verify your installation:
-
Check that Git AST is in your path:
git-ast --version
-
Test on a sample file:
# Create a test file echo 'fn main() { println!("Hello, world!"); }' > test.rs # Add and commit git add test.rs git commit -m "Test Git AST" # This should process the file through Git AST
If you encounter issues during installation:
-
Command not found:
- Ensure Git AST is in your PATH
- Try using the full path to the executable
-
Filter not working:
- Check your
.gitattributesfile - Verify Git config settings with
git config --local --list | grep filter
- Check your
-
Parse errors:
- Ensure source files are syntactically valid
- Check for unsupported language features
- GitHub Issues: Report bugs or installation problems on our GitHub repository
- Documentation: Refer to the Architecture documentation for more details on how Git AST works
After installation:
- Learn about using Git AST in your daily workflow
- Explore key concepts to better understand how Git AST works
- Consider contributing to the project