rw_git 1.0.3 copy "rw_git: ^1.0.3" to clipboard
rw_git: ^1.0.3 copied to clipboard

A git wrapper that facilitates the execution of various useful git commands.

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);

  // Retrieve and count all the tags.
  List<String> tags = await rwGit.fetchTags(localDirectoryToCloneInto);
  print("Number of tags: ${tags.length}");

  // Count all commits between two tags.
  List<String> listOfCommitsBetweenTwoTags =
      await rwGit.getCommitsBetween(localDirectoryToCloneInto, oldTag, newTag);
  print(
      "Number of commits between $oldTag and $newTag: ${listOfCommitsBetweenTwoTags.length}");

  // Retrieve lines of code inserted, deleted and number of changed files.
  ShortStatDto shortStatDto =
      await rwGit.stats(localDirectoryToCloneInto, oldTag, newTag);
  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";
}
2
likes
140
pub points
53%
popularity

Publisher

verified publisherpub.gbrandtio.dev

A git wrapper that facilitates the execution of various useful git commands.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

git, path

More

Packages that depend on rw_git