createWorktree function

Future<String?> createWorktree({
  1. String? dir,
  2. required String path,
  3. required String branch,
  4. bool createBranch = true,
})

Create a git worktree.

Implementation

Future<String?> createWorktree({
  String? dir,
  required String path,
  required String branch,
  bool createBranch = true,
}) async {
  final args = ['worktree', 'add'];
  if (createBranch) args.add('-b');
  args.addAll([path, if (!createBranch) branch]);

  final result = await runGit(args, workingDirectory: dir);
  return result.success ? path : null;
}