git_on_dart 0.1.1 copy "git_on_dart: ^0.1.1" to clipboard
git_on_dart: ^0.1.1 copied to clipboard

Pure Dart git implementation optimized for Flutter mobile apps. Provides local and remote git operations (init, commit, push, pull, merge, rebase) with HTTPS/SSH authentication.

git_on_dart #

pub package License: MIT

A pure Dart implementation of Git, optimized for Flutter mobile applications (Android & iOS). Build native Git clients for mobile with full local and remote repository support.

Features #

Local Operations #

  • Repository Management: init, open
  • Staging: add, status
  • Commits: commit, log
  • Branching: create, delete, list branches
  • Checkout: switch branches and restore files
  • Merging: 3-way merge with conflict detection
  • Rebasing: interactive rebase support

Remote Operations #

  • Remote Management: add, remove, list remotes
  • Fetch: download refs and objects from remote
  • Push: upload commits to remote (with force option)
  • Pull: fetch and merge in one operation
  • Authentication: HTTPS (token, basic auth), SSH (key-based)

Technical Features #

  • 🚀 Git Protocol Compatible: Standard DIRC index format, SHA-1 hashing, tree objects
  • 📱 Mobile Optimized: Memory-efficient streaming I/O, async/await throughout
  • 🔒 Type Safe: Strong typing with comprehensive error handling via GitResult<T>
  • Flutter Ready: Works seamlessly with Flutter for Android and iOS
  • 🌐 Cross-Platform: Android, iOS, Linux, macOS, Windows

Installation #

Add to your pubspec.yaml:

dependencies:
  git_on_dart: ^0.1.0

Then run:

dart pub get

Quick Start #

Initialize a Repository #

import 'package:git_on_dart/git_on_dart.dart';

// Create a new repository
final repo = await GitRepository.init('/path/to/repo');

// Or open an existing one
final repo = await GitRepository.open('/path/to/repo');

Basic Workflow #

// Stage files
final addOp = AddOperation(repo);
await addOp.addFiles(['lib/main.dart', 'pubspec.yaml']);

// Check status
final statusOp = StatusOperation(repo);
final status = await statusOp.getStatus();
print('Modified: ${status.modified.length}');
print('Staged: ${status.staged.length}');

// Commit changes
final commitOp = CommitOperation(repo);
final author = GitAuthor(
  name: 'Your Name',
  email: 'your@email.com',
  timestamp: DateTime.now(),
);
final result = await commitOp.commit(
  message: 'Initial commit',
  author: author,
);
print('Commit: ${result.data}');

Branching and Merging #

// Create and switch to a new branch
await repo.refManager.createBranch('feature-branch');
final checkoutOp = CheckoutOperation(repo);
await checkoutOp.checkout('feature-branch');

// Make changes and commit...

// Switch back and merge
await checkoutOp.checkout('main');
final mergeOp = MergeOperation(repo);
final mergeResult = await mergeOp.merge('feature-branch');

if (mergeResult.hasConflicts) {
  print('Conflicts in: ${mergeResult.conflicts.keys}');
  // Handle conflicts...
}

Remote Operations #

// Add a remote
final remoteManager = RemoteManager(repo);
await remoteManager.addRemote(
  name: 'origin',
  url: 'https://github.com/username/repo.git',
);

// Configure authentication
final credentials = HttpsCredentials.token('your_github_token');

// Push changes
final pushOp = PushOperation(repo);
final pushResult = await pushOp.push(
  remoteName: 'origin',
  refspec: 'main:main',
  credentials: credentials,
);

// Pull changes
final pullOp = PullOperation(repo);
final pullResult = await pullOp.pull(
  remoteName: 'origin',
  branch: 'main',
  credentials: credentials,
);

SSH Authentication #

// Using SSH keys
final sshCreds = SshCredentials(
  privateKeyPath: '/path/to/id_rsa',
  passphrase: 'optional_passphrase',
);

await pushOp.push(
  remoteName: 'origin',
  refspec: 'main:main',
  credentials: sshCreds,
);

Error Handling #

All operations return GitResult<T> for consistent error handling:

final result = await commitOp.commit(
  message: 'My commit',
  author: author,
);

if (result.isSuccess) {
  print('Commit hash: ${result.data}');
} else {
  print('Error: ${result.error?.message}');
  print('Type: ${result.error?.type}');
}

Example #

See the example directory for a complete working example demonstrating:

  • Repository initialization
  • File staging and commits
  • Branch management
  • Merge operations
  • Status checking

Run it with:

dart run example/git_demo.dart

Architecture #

  • Core: Repository management, object database, index, refs
  • Models: Git objects (blob, tree, commit), authors, results
  • Operations: Modular operations for each git command
  • Remote: Remote repository management and network operations

For detailed implementation notes, see IMPLEMENTATION.md.

Testing #

The package includes comprehensive test coverage:

dart test
  • 12 local operation tests
  • 31 remote operation tests
  • Full workflow integration tests

Limitations #

  • Pack Protocol: Simplified implementation (full git pack protocol in progress)
  • SSH Support: Requires external SSH library for actual SSH operations
  • Large Files: Optimized for mobile, may need adjustments for very large repos

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

MIT License - see LICENSE file for details.

1
likes
0
points
94
downloads

Publisher

unverified uploader

Weekly Downloads

Pure Dart git implementation optimized for Flutter mobile apps. Provides local and remote git operations (init, commit, push, pull, merge, rebase) with HTTPS/SSH authentication.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

archive, crypto, path, path_provider

More

Packages that depend on git_on_dart