Created
April 5, 2023 16:38
-
-
Save mack-at-pieces/cd700ea26e89e715c8dd384e1f43b3ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Use `git ls-files` to get all of the files in source control | |
Future<List<String>> gitLsFiles(String directory) async { | |
/// Check that git is available on the command line | |
if (await Process.run('git', []).then((value) => false).catchError((e) => true)) { | |
return []; | |
} | |
/// Run Git ls-files to get all files not ignored by git ignore | |
return Process.run('git', ['ls-files'], workingDirectory: directory).then((value) { | |
/// If there is no git or some other error occurs, return an empty list, | |
/// meaning no files in source control in this particular directory | |
if (value.stderr.isNotEmpty) { | |
return []; | |
} | |
/// Otherwise split the response by new lines | |
return value.stdout.toString().split('\n'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tsavo-at-pieces This is a great snippet we use in Snippet Discovery to parse out non-git-tracked files.