git icon indicating copy to clipboard operation
git copied to clipboard

Add ahead-behind

Open Jamminroot opened this issue 2 years ago • 0 comments

Hey! Thanks for a great tool.

Having an ability to get commits ahead\behind would also be great.

Rough implementation would be something like (git_dir.dart)

  static final RegExp _aheadRegExp = RegExp(r'^\*.*[\[| \,].*ahead (.*?)[\]|\,]');
  static final RegExp _behindRegExp = RegExp(r'^\*.*[\[| \,].*behind (.*?)[\]|\,]');

  Future<List<int>> commitsAheadBehind() async {
    final pr = await runCommand(['branch', '-v']);
    var output = pr.stdout as String;
    var ahead = _aheadRegExp.hasMatch(output)? int.parse(_aheadRegExp.firstMatch(output)?.group(1) ?? "0") : 0;
    var behind = _behindRegExp.hasMatch(output)? int.parse(_behindRegExp.firstMatch(output)?.group(1) ?? "0") : 0;
    return [ahead, behind];
  }

Jamminroot avatar Jul 23 '21 13:07 Jamminroot