Skip to content

Commit f8842ae

Browse files
authored
Merge pull request #3 from eugener/develop
Status and branching APIs
2 parents 8a55f43 + 9ecc416 commit f8842ae

22 files changed

+3537
-389
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Rust
1+
name: CI
22

33
on:
44
push:
5-
branches: [ "master" ]
5+
branches: [ "master", "develop" ]
66
paths-ignore:
77
- '**.md' # Ignores all Markdown files
88
pull_request:
9-
branches: [ "master" ]
9+
branches: [ "master", "develop" ]
1010
paths-ignore:
1111
- '**.md' # Ignores all Markdown files
1212

@@ -38,6 +38,11 @@ jobs:
3838
restore-keys: |
3939
${{ runner.os }}-cargo-
4040
41+
- name: Configure git for tests
42+
run: |
43+
git config --global user.name "Test User"
44+
git config --global user.email "[email protected]"
45+
4146
- name: Check formatting
4247
run: cargo fmt -- --check
4348

@@ -49,3 +54,12 @@ jobs:
4954

5055
- name: Run tests
5156
run: cargo test --verbose
57+
58+
- name: Test examples compile and run
59+
run: |
60+
echo "Testing examples..."
61+
for example in examples/*.rs; do
62+
example_name=$(basename "$example" .rs)
63+
echo "Building example: $example_name"
64+
cargo build --example "$example_name"
65+
done

.github/workflows/release.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Release to crates.io
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Install Rust toolchain
19+
uses: actions-rust-lang/setup-rust-toolchain@v1
20+
with:
21+
toolchain: stable
22+
components: rustfmt, clippy
23+
24+
- name: Cache dependencies
25+
uses: actions/cache@v4
26+
with:
27+
path: |
28+
~/.cargo/registry
29+
~/.cargo/git
30+
target
31+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
32+
restore-keys: |
33+
${{ runner.os }}-cargo-
34+
35+
- name: Verify release tag matches Cargo.toml version
36+
run: |
37+
# Extract version from Cargo.toml
38+
CARGO_VERSION=$(grep '^version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
39+
# Extract version from GitHub release tag (remove 'v' prefix if present)
40+
RELEASE_VERSION=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v//')
41+
42+
echo "Cargo.toml version: $CARGO_VERSION"
43+
echo "Release tag version: $RELEASE_VERSION"
44+
45+
if [ "$CARGO_VERSION" != "$RELEASE_VERSION" ]; then
46+
echo "Version mismatch! Cargo.toml version ($CARGO_VERSION) does not match release tag ($RELEASE_VERSION)"
47+
exit 1
48+
fi
49+
50+
echo "Version verification passed"
51+
52+
- name: Format check
53+
run: cargo fmt --all -- --check
54+
55+
- name: Clippy check
56+
run: cargo clippy --all-targets --all-features -- -D warnings
57+
58+
- name: Run tests
59+
run: cargo test --all-features
60+
61+
- name: Verify examples compile and run
62+
run: |
63+
echo "Testing examples..."
64+
for example in examples/*.rs; do
65+
example_name=$(basename "$example" .rs)
66+
echo "Building example: $example_name"
67+
cargo build --example "$example_name"
68+
done
69+
70+
# Test a few key examples to make sure they work
71+
echo "Running basic_usage example..."
72+
timeout 30s cargo run --example basic_usage || echo "Example completed or timed out"
73+
74+
echo "Running repository_operations example..."
75+
timeout 30s cargo run --example repository_operations || echo "Example completed or timed out"
76+
77+
- name: Build release
78+
run: cargo build --release --all-features
79+
80+
- name: Verify package contents
81+
run: |
82+
cargo package --list
83+
echo "Package contents verified"
84+
85+
- name: Dry run publish
86+
run: cargo publish --dry-run --all-features
87+
88+
- name: Publish to crates.io
89+
run: cargo publish --all-features
90+
env:
91+
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
92+
93+
- name: Create publish summary
94+
run: |
95+
echo "## Release Summary" >> $GITHUB_STEP_SUMMARY
96+
echo "" >> $GITHUB_STEP_SUMMARY
97+
echo " **Published to crates.io**: \`rustic-git v${{ github.event.release.tag_name }}\`" >> $GITHUB_STEP_SUMMARY
98+
echo "" >> $GITHUB_STEP_SUMMARY
99+
echo "### Package Details" >> $GITHUB_STEP_SUMMARY
100+
echo "- **Version**: ${{ github.event.release.tag_name }}" >> $GITHUB_STEP_SUMMARY
101+
echo "- **Registry**: [crates.io](https://crates.io/crates/rustic-git)" >> $GITHUB_STEP_SUMMARY
102+
echo "- **Documentation**: [docs.rs](https://docs.rs/rustic-git)" >> $GITHUB_STEP_SUMMARY
103+
echo "" >> $GITHUB_STEP_SUMMARY
104+
echo "### Quality Checks Passed" >> $GITHUB_STEP_SUMMARY
105+
echo "- Code formatting (rustfmt)" >> $GITHUB_STEP_SUMMARY
106+
echo "- Linting (clippy with zero warnings)" >> $GITHUB_STEP_SUMMARY
107+
echo "- All tests passing" >> $GITHUB_STEP_SUMMARY
108+
echo "- Examples compile and run" >> $GITHUB_STEP_SUMMARY
109+
echo "- Version verification" >> $GITHUB_STEP_SUMMARY

CLAUDE.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,42 @@
1818
- **Command execution**: Use std::process::Command with proper error handling and stderr capture
1919

2020
## Implementation
21-
- Available methods: Repository::init(path, bare), Repository::open(path), Repository::status(), Repository::add(paths), Repository::add_all(), Repository::add_update(), Repository::commit(message), Repository::commit_with_author(message, author)
22-
- Status functionality: GitStatus with FileStatus enum, files as Box<[(FileStatus, String)]>
23-
- Add functionality: Stage specific files, all changes, or tracked file updates
24-
- Commit functionality: Create commits and return Hash of created commit
25-
- Hash type: Universal git object hash representation with short() and Display methods
26-
- Utility functions: git(args, working_dir) -> Result<String>, git_raw(args, working_dir) -> Result<Output>
27-
- Command modules: status.rs, add.rs, commit.rs (in src/commands/)
28-
- Core types: Hash (in src/types.rs)
21+
- **Repository lifecycle**: Repository::init(path, bare), Repository::open(path)
22+
- **Status functionality**: Enhanced GitStatus API with separate staged/unstaged file tracking
23+
- GitStatus with entries as Box<[FileEntry]> for immutable, efficient storage
24+
- FileEntry contains PathBuf, IndexStatus, and WorktreeStatus for precise Git state representation
25+
- IndexStatus enum: Clean, Modified, Added, Deleted, Renamed, Copied (with const from_char/to_char methods)
26+
- WorktreeStatus enum: Clean, Modified, Deleted, Untracked, Ignored (with const from_char/to_char methods)
27+
- API methods: staged_files(), unstaged_files(), untracked_entries(), files_with_index_status(), files_with_worktree_status()
28+
- **Staging functionality**: Repository::add(paths), Repository::add_all(), Repository::add_update()
29+
- **Commit functionality**: Repository::commit(message), Repository::commit_with_author(message, author) - return Hash of created commit
30+
- **Branch functionality**: Complete branch operations with type-safe API
31+
- Repository::branches() -> Result<BranchList> - list all branches with comprehensive filtering
32+
- Repository::current_branch() -> Result<Option<Branch>> - get currently checked out branch
33+
- Repository::create_branch(name, start_point) -> Result<Branch> - create new branch
34+
- Repository::delete_branch(branch, force) -> Result<()> - delete branch with safety checks
35+
- Repository::checkout(branch) -> Result<()> - switch to existing branch
36+
- Repository::checkout_new(name, start_point) -> Result<Branch> - create and checkout branch
37+
- Branch struct: name, branch_type, is_current, commit_hash, upstream tracking
38+
- BranchType enum: Local, RemoteTracking
39+
- BranchList: Box<[Branch]> with iterator methods (iter, local, remote), search (find, find_by_short_name), counting (len, local_count, remote_count)
40+
- **Commit history & log operations**: Multi-level API for comprehensive commit analysis
41+
- Repository::log() -> Result<CommitLog> - get all commits with simple API
42+
- Repository::recent_commits(count) -> Result<CommitLog> - get recent N commits
43+
- Repository::log_with_options(options) -> Result<LogOptions> - advanced queries with filters
44+
- Repository::log_range(from, to) -> Result<CommitLog> - commits between two points
45+
- Repository::log_for_paths(paths) -> Result<CommitLog> - commits affecting specific paths
46+
- Repository::show_commit(hash) -> Result<CommitDetails> - detailed commit information
47+
- Commit struct: hash, author, committer, message, timestamp, parents
48+
- CommitLog: Box<[Commit]> with iterator-based filtering (with_message_containing, since, until, merges_only, no_merges, find_by_hash)
49+
- LogOptions builder: max_count, since/until dates, author/committer filters, grep, paths, merge filtering
50+
- Author struct: name, email, timestamp with Display implementation
51+
- CommitMessage: subject and optional body parsing
52+
- CommitDetails: full commit info including file changes and diff stats
53+
- **Core types**: Hash (in src/types.rs), IndexStatus, WorktreeStatus, FileEntry (in src/commands/status.rs), Branch, BranchList, BranchType (in src/commands/branch.rs), Commit, CommitLog, Author, CommitMessage, CommitDetails, LogOptions (in src/commands/log.rs)
54+
- **Utility functions**: git(args, working_dir) -> Result<String>, git_raw(args, working_dir) -> Result<Output>
55+
- **Command modules**: status.rs, add.rs, commit.rs, branch.rs, log.rs (in src/commands/)
56+
- **Testing**: 101+ tests covering all functionality with comprehensive edge cases
2957
- Run `cargo fmt && cargo build && cargo test && cargo clippy --all-targets --all-features -- -D warnings` after code changes
3058
- Make sure all examples are running
3159

@@ -34,9 +62,11 @@ The `examples/` directory contains comprehensive demonstrations of library funct
3462

3563
- **basic_usage.rs**: Complete workflow from init to commit - demonstrates fundamental rustic-git usage
3664
- **repository_operations.rs**: Repository lifecycle - init regular/bare repos, open existing repos, error handling
37-
- **status_checking.rs**: GitStatus and FileStatus usage - all status query methods and file state filtering
65+
- **status_checking.rs**: Enhanced GitStatus API usage - staged/unstaged file queries, IndexStatus/WorktreeStatus filtering, comprehensive status analysis
3866
- **staging_operations.rs**: Staging operations - add(), add_all(), add_update() with before/after comparisons
3967
- **commit_workflows.rs**: Commit operations and Hash type - commit(), commit_with_author(), Hash methods
68+
- **branch_operations.rs**: Complete branch management - create/delete/checkout branches, BranchList filtering, branch type handling, search operations
69+
- **commit_history.rs**: Comprehensive commit history & log operations - demonstrates all commit querying APIs, filtering, analysis, and advanced LogOptions usage
4070
- **error_handling.rs**: Comprehensive error handling patterns - GitError variants, recovery strategies
4171

4272
Run examples with: `cargo run --example <example_name>`

0 commit comments

Comments
 (0)