Skip to main content

gg_git 4.7.0 copy "gg_git: ^4.7.0" to clipboard
gg_git: ^4.7.0 copied to clipboard

A collection of git helper scripts for repository checks and other utilities.

gg_git #

A collection of git helper scripts for repository checks and other utilities.

SSH host keys #

SshHostKeys helps when git cannot connect to an ssh remote: it tells an unknown host (isUnknownHost) from a changed host key (isChangedHostKey) and a refused user key (isKeyRejected), reads the key an unknown host presents without trusting it (scan), tells the developer what to do next (setupHint), compares its fingerprint with the fingerprints GitHub and Azure DevOps publish (checkFingerprint) and adds it to ~/.ssh/known_hosts (trust).

final hostKeys = SshHostKeys();
final host = SshHostKeys.hostOf(url)!;
for (final key in await hostKeys.scan(url)) {
  print('${key.typeName} ${key.fingerprint} '
      '${SshHostKeys.checkFingerprint(host, key)}');
}

Test helpers #

package:gg_git/gg_git_test_helpers.dart provides helpers that create real git repositories for tests: initGit, initLocalAndRemoteGit, addAndCommitSampleFile and friends.

Cached test repos #

Building a repository spawns several git processes. When every test's setUp does this, test suites become slow. The cached variants build a fixture only once per test file and deliver a fresh filesystem copy per call — no git processes are spawned for a copy:

setUp(() async {
  d = await Directory.systemTemp.createTemp();
  await initCachedRepo(
    d,
    key: 'my_fixture',
    build: (repo) async {
      await initGit(repo);
      await addAndCommitSampleFile(repo);
    },
  );
});

For a local repository wired to a bare remote use initCachedRepoPair. It copies both directories together and rewires origin to the copied remote via git remote set-url — the only git process spawned per copy:

setUp(() async {
  (d, dRemote) = await initCachedRepoPair(
    key: 'my_pair',
    build: (local, remote) async {
      await initLocalGit(local);
      await initRemoteGit(remote);
      await addRemoteToLocal(local: local, remote: remote);
    },
  );
});

initCachedGit and initCachedLocalAndRemoteGit are cached drop-in variants of initGit and initLocalAndRemoteGit.

Notes:

  • Within one test file a key must always map to the same recipe — the first builder wins. Keys starting with gg_git/ are reserved.
  • Template directories live in the system temp directory and are kept for the lifetime of the test process (similar to the temp directories of initTestDir). The operating system cleans them up eventually.
  • Tests own the copies and should delete them in tearDown as usual.
1
likes
160
points
5.04k
downloads

Documentation

API reference

Publisher

verified publisherinlavigo.com

Weekly Downloads

A collection of git helper scripts for repository checks and other utilities.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

args, crypto, gg_args, gg_console_colors, gg_hash, gg_is_github, gg_log, gg_process, gg_status_printer, meta, mocktail, path

More

Packages that depend on gg_git