rw_git 2.0.0
rw_git: ^2.0.0 copied to clipboard
A Dart git wrapper and MCP server that facilitates the execution of various git commands and AI repository analysis.
example/rw_git_example.dart
import 'dart:io';
import 'package:rw_git/rw_git.dart';
void main() async {
// Initialize RwGit service.
final rwGit = RwGit();
// Initializations.
final localDirectoryName = "RW_GIT";
final oldTag = "v6.0.8";
final newTag = "v7.0.0";
final repositoryToClone =
"https://github.com/jasontaylordev/CleanArchitecture";
// Create a local directory and clone into it.
String localDirectoryToCloneInto =
_createCheckoutDirectory(localDirectoryName);
rwGit.clone(localDirectoryToCloneInto, repositoryToClone);
// 2. Retrieve the tags of the repository
List<String> tags =
(await rwGit.fetchTags(localDirectoryToCloneInto)).getOrThrow();
print("Number of tags: ${tags.length}");
// 3. Get the commits between two tags
List<String> listOfCommitsBetweenTwoTags =
(await rwGit.getCommitsBetween(localDirectoryToCloneInto, oldTag, newTag))
.getOrThrow();
print(
"Number of commits between $oldTag and $newTag: ${listOfCommitsBetweenTwoTags.length}");
// Retrieve lines of code inserted, deleted and number of changed files
// between two tags.
ShortStatDto shortStatDto =
(await rwGit.stats(localDirectoryToCloneInto, oldTag, newTag))
.getOrThrow();
print('Number of lines inserted: ${shortStatDto.insertions}'
' Number of lines deleted: ${shortStatDto.deletions}'
' Number of files changed: ${shortStatDto.numberOfChangedFiles}');
}
/// Creates the directory where the repository will be checked out,
/// If the directory already exists, it will delete it along with any content inside
/// and a new one will be created.
String _createCheckoutDirectory(String directoryName) {
Directory checkoutDirectory = Directory(directoryName);
try {
checkoutDirectory.deleteSync(recursive: true);
} catch (e) {
// Handle the exception
}
checkoutDirectory.createSync();
return "${Directory.current.path}\\$directoryName";
}