File tree 27 files changed +212
-137
lines changed
27 files changed +212
-137
lines changed Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/git.dart' ;
@@ -13,10 +11,14 @@ class AddCommand extends Command<int> {
13
11
@override
14
12
final description = 'Add file contents to the index' ;
15
13
14
+ final String currentDir;
15
+
16
+ AddCommand (this .currentDir);
17
+
16
18
@override
17
19
int run () {
18
20
// FIXME: if gitRootDir is not valid give an error!
19
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
21
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
20
22
var repo = GitRepository .load (gitRootDir);
21
23
22
24
var pathSpec = argResults! .arguments[0 ];
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/git.dart' ;
@@ -15,15 +13,17 @@ class BranchCommand extends Command<int> {
15
13
@override
16
14
final description = 'List, create, or delete branches' ;
17
15
18
- BranchCommand () {
16
+ final String currentDir;
17
+
18
+ BranchCommand (this .currentDir) {
19
19
argParser.addOption ('set-upstream-to' );
20
20
argParser.addFlag ('all' , abbr: 'a' , defaultsTo: false );
21
21
argParser.addFlag ('delete' , abbr: 'd' , defaultsTo: false );
22
22
}
23
23
24
24
@override
25
25
int run () {
26
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
26
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
27
27
var repo = GitRepository .load (gitRootDir);
28
28
29
29
var showAll = argResults! ['all' ] as bool ? ;
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
3
import 'dart:convert' ;
4
- import 'dart:io' ;
5
4
6
5
import 'package:args/command_runner.dart' ;
7
6
@@ -16,9 +15,13 @@ class CatFileCommand extends Command<int> {
16
15
final description =
17
16
'Provide content or type and size information for repository objects' ;
18
17
18
+ final String currentDir;
19
+
20
+ CatFileCommand (this .currentDir);
21
+
19
22
@override
20
23
int run () {
21
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
24
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
22
25
var repo = GitRepository .load (gitRootDir);
23
26
24
27
var objectSha1 = argResults! .arguments[1 ];
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/git.dart' ;
@@ -15,13 +13,15 @@ class CheckoutCommand extends Command<int> {
15
13
@override
16
14
final description = 'Switch branches or restore working tree files' ;
17
15
18
- CheckoutCommand () {
16
+ final String currentDir;
17
+
18
+ CheckoutCommand (this .currentDir) {
19
19
argParser.addOption ('branch' , abbr: 'b' , defaultsTo: '' );
20
20
}
21
21
22
22
@override
23
23
int run () {
24
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
24
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
25
25
var repo = GitRepository .load (gitRootDir);
26
26
27
27
var branchName = argResults! ['branch' ] as String ;
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/diff_commit.dart' ;
@@ -16,7 +14,9 @@ class DiffCommand extends Command<int> {
16
14
final description =
17
15
'Show changes between commits, commit and working tree, etc' ;
18
16
19
- DiffCommand () {
17
+ final String currentDir;
18
+
19
+ DiffCommand (this .currentDir) {
20
20
argParser.addFlag ('raw' );
21
21
}
22
22
@@ -28,7 +28,7 @@ class DiffCommand extends Command<int> {
28
28
return 1 ;
29
29
}
30
30
31
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
31
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
32
32
var repo = GitRepository .load (gitRootDir);
33
33
34
34
var fromStr = argResults! .arguments[0 ];
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/diff_tree.dart' ;
@@ -17,9 +15,13 @@ class DiffTreeCommand extends Command<int> {
17
15
final description =
18
16
'Compares the content and mode of blobs found via two tree objects' ;
19
17
18
+ final String currentDir;
19
+
20
+ DiffTreeCommand (this .currentDir);
21
+
20
22
@override
21
23
int run () {
22
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
24
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
23
25
var repo = GitRepository .load (gitRootDir);
24
26
25
27
var hash = argResults! .arguments[0 ];
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/git.dart' ;
@@ -13,9 +11,13 @@ class DumpIndexCommand extends Command<int> {
13
11
@override
14
12
final description = 'Prints the contents of the .git/index' ;
15
13
14
+ final String currentDir;
15
+
16
+ DumpIndexCommand (this .currentDir);
17
+
16
18
@override
17
19
int run () {
18
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
20
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
19
21
var repo = GitRepository .load (gitRootDir);
20
22
21
23
var index = repo.indexStorage.readIndex ();
Original file line number Diff line number Diff line change 3
3
import 'dart:io' ;
4
4
5
5
import 'package:args/command_runner.dart' ;
6
+ import 'package:path/path.dart' as p;
6
7
7
8
import 'package:dart_git/git.dart' ;
8
9
import 'package:dart_git/plumbing/git_hash.dart' ;
@@ -16,7 +17,9 @@ class HashObjectCommand extends Command<int> {
16
17
final description =
17
18
'Compute object ID and optionally creates a blob from a file' ;
18
19
19
- HashObjectCommand () {
20
+ final String currentDir;
21
+
22
+ HashObjectCommand (this .currentDir) {
20
23
argParser.addOption (
21
24
'type' ,
22
25
abbr: 't' ,
@@ -39,10 +42,13 @@ class HashObjectCommand extends Command<int> {
39
42
return 1 ;
40
43
}
41
44
var filePath = argResults! .rest[0 ];
45
+ if (! File (filePath).existsSync ()) {
46
+ filePath = p.join (currentDir, filePath);
47
+ }
42
48
var rawData = File (filePath).readAsBytesSync ();
43
49
var hash = GitHash .compute (rawData);
44
50
45
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
51
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
46
52
var repo = GitRepository .load (gitRootDir);
47
53
48
54
var fmt = argResults! ['type' ] as String ;
Original file line number Diff line number Diff line change @@ -13,7 +13,9 @@ class InitCommand extends Command<int> {
13
13
final description =
14
14
'Create an empty Git repository or reinitialize an existing one' ;
15
15
16
- InitCommand () {
16
+ final String currentDir;
17
+
18
+ InitCommand (this .currentDir) {
17
19
argParser.addFlag ('quiet' , abbr: 'q' , defaultsTo: false );
18
20
argParser.addOption ('initial-branch' , abbr: 'b' , defaultsTo: 'main' );
19
21
}
@@ -25,7 +27,7 @@ class InitCommand extends Command<int> {
25
27
return 1 ;
26
28
}
27
29
28
- var path = argResults! .rest.first;
30
+ var path = p. join (currentDir, argResults! .rest.first) ;
29
31
var defaultBranch = argResults! ['initial-branch' ] as String ;
30
32
GitRepository .init (path, defaultBranch: defaultBranch);
31
33
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
3
import 'dart:convert' ;
4
- import 'dart:io' ;
5
4
6
5
import 'package:args/command_runner.dart' ;
7
6
@@ -17,9 +16,13 @@ class LogCommand extends Command<int> {
17
16
@override
18
17
final description = 'Show commit logs' ;
19
18
19
+ final String currentDir;
20
+
21
+ LogCommand (this .currentDir);
22
+
20
23
@override
21
24
int run () {
22
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
25
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
23
26
var repo = GitRepository .load (gitRootDir);
24
27
25
28
GitHash ? sha;
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/git.dart' ;
@@ -16,11 +14,15 @@ class LsTreeCommand extends Command<int> {
16
14
@override
17
15
final description = 'List the contents of a tree object' ;
18
16
17
+ final String currentDir;
18
+
19
+ LsTreeCommand (this .currentDir);
20
+
19
21
@override
20
22
int run () {
21
23
var objectSha1 = argResults! .rest.first;
22
24
23
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
25
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
24
26
var repo = GitRepository .load (gitRootDir);
25
27
26
28
var objRes = repo.objStorage.read (GitHash (objectSha1));
Original file line number Diff line number Diff line change @@ -14,7 +14,9 @@ class MergeCommand extends Command<int> {
14
14
@override
15
15
final description = 'Join two or more development histories together' ;
16
16
17
- MergeCommand () {
17
+ final String currentDir;
18
+
19
+ MergeCommand (this .currentDir) {
18
20
argParser.addOption ('strategy-option' , abbr: 'X' );
19
21
argParser.addOption ('message' , abbr: 'm' );
20
22
}
@@ -28,7 +30,7 @@ class MergeCommand extends Command<int> {
28
30
}
29
31
30
32
var branchName = args[0 ];
31
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
33
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
32
34
var repo = GitRepository .load (gitRootDir);
33
35
var branchCommit = repo.branchCommit (branchName);
34
36
if (branchCommit == null ) {
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/git.dart' ;
@@ -14,7 +12,9 @@ class MergeBaseCommand extends Command<int> {
14
12
@override
15
13
final description = 'Find as good common ancestors as possible for a merge' ;
16
14
17
- MergeBaseCommand () {
15
+ final String currentDir;
16
+
17
+ MergeBaseCommand (this .currentDir) {
18
18
argParser.addFlag ('independent' , defaultsTo: false );
19
19
}
20
20
@@ -26,7 +26,7 @@ class MergeBaseCommand extends Command<int> {
26
26
return 1 ;
27
27
}
28
28
29
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
29
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
30
30
var repo = GitRepository .load (gitRootDir);
31
31
32
32
var aHash = GitHash (args[0 ]);
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/command_runner.dart' ;
6
4
7
5
import 'package:dart_git/file_mtime_builder.dart' ;
@@ -14,13 +12,15 @@ class MTimeBuilderCommand extends Command<int> {
14
12
@override
15
13
final description = 'Internal Dart-Git tools' ;
16
14
17
- MTimeBuilderCommand () {
15
+ final String currentDir;
16
+
17
+ MTimeBuilderCommand (this .currentDir) {
18
18
argParser.addFlag ('debug' , abbr: 'd' , defaultsTo: false );
19
19
}
20
20
21
21
@override
22
22
int run () {
23
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
23
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
24
24
var repo = GitRepository .load (gitRootDir);
25
25
26
26
var builder = FileMTimeBuilder ();
Original file line number Diff line number Diff line change 1
1
// ignore_for_file: avoid_print
2
2
3
- import 'dart:io' ;
4
-
5
3
import 'package:args/args.dart' ;
6
4
import 'package:args/command_runner.dart' ;
7
5
@@ -17,15 +15,17 @@ class RemoteCommand extends Command<int> {
17
15
final ArgParser addArgParser = ArgParser ();
18
16
final ArgParser rmArgParser = ArgParser ();
19
17
20
- RemoteCommand () {
18
+ final String currentDir;
19
+
20
+ RemoteCommand (this .currentDir) {
21
21
argParser.addFlag ('verbose' , abbr: 'v' , defaultsTo: false );
22
22
argParser.addCommand ('add' , addArgParser);
23
23
argParser.addCommand ('rm' , rmArgParser);
24
24
}
25
25
26
26
@override
27
27
int run () {
28
- var gitRootDir = GitRepository .findRootDir (Directory .current.path )! ;
28
+ var gitRootDir = GitRepository .findRootDir (currentDir )! ;
29
29
var repo = GitRepository .load (gitRootDir);
30
30
31
31
var verbose = argResults! ['verbose' ] as bool ? ;
You can’t perform that action at this time.
0 commit comments