@@ -39,32 +39,41 @@ fn set_up_git_repos(config: &mut Config) -> TempDir {
39
39
let file_name = input_path. file_name ( ) . unwrap ( ) ;
40
40
41
41
let dir_path = tmp. path ( ) . join ( file_name) ;
42
- // TODO: allow some annotations for configuring the git structure. (e.g. branches/tags)
42
+
43
+ let run = |cmd : & mut Command | {
44
+ assert ! ( cmd. output( ) . unwrap( ) . status. success( ) ) ;
45
+ } ;
46
+
47
+ let run_in_dir = |cmd : & mut Command | {
48
+ run ( cmd. current_dir ( & dir_path) ) ;
49
+ } ;
43
50
44
51
// The rust stdlib doesn't have anything for recursively copying a directory. There are
45
52
// some crates for that, but it's easier just to shell out.
46
- Command :: new ( "cp" )
53
+ run ( Command :: new ( "cp" )
47
54
. arg ( "-r" )
48
55
. arg ( & input_path)
49
- . arg ( tmp. path ( ) )
50
- . output ( )
51
- . unwrap ( ) ;
52
-
53
- Command :: new ( "git" )
54
- . arg ( "init" )
55
- . current_dir ( & dir_path)
56
- . output ( )
57
- . unwrap ( ) ;
58
- Command :: new ( "git" )
59
- . args ( [ "add" , "--all" ] )
60
- . current_dir ( & dir_path)
61
- . output ( )
62
- . unwrap ( ) ;
63
- Command :: new ( "git" )
64
- . args ( [ "commit" , "-m" , "initial" ] )
65
- . current_dir ( & dir_path)
66
- . output ( )
67
- . unwrap ( ) ;
56
+ . arg ( tmp. path ( ) ) ) ;
57
+
58
+ // We have some hacky ways to test branch/tag fetching: if the input contains a tag.txt file,
59
+ // make a git tag named with the contents of that file. If the input contains a branch.txt file,
60
+ // make a git branch named with the contents of that file.
61
+ let tag = std:: fs:: read_to_string ( dir_path. join ( "tag.txt" ) ) . ok ( ) ;
62
+ let branch = std:: fs:: read_to_string ( dir_path. join ( "branch.txt" ) ) . ok ( ) ;
63
+
64
+ run_in_dir ( Command :: new ( "git" ) . arg ( "init" ) ) ;
65
+
66
+ if let Some ( branch) = branch {
67
+ run_in_dir ( Command :: new ( "git" ) . args ( [ "commit" , "-m" , "initial" , "--allow-empty" ] ) ) ;
68
+ run_in_dir ( Command :: new ( "git" ) . args ( [ "checkout" , "-b" , branch. trim ( ) ] ) ) ;
69
+ }
70
+
71
+ run_in_dir ( Command :: new ( "git" ) . args ( [ "add" , "--all" ] ) ) ;
72
+ run_in_dir ( Command :: new ( "git" ) . args ( [ "commit" , "-m" , "initial" ] ) ) ;
73
+
74
+ if let Some ( tag) = tag {
75
+ run_in_dir ( Command :: new ( "git" ) . args ( [ "tag" , tag. trim ( ) ] ) ) ;
76
+ }
68
77
69
78
let orig_url = gix:: Url :: try_from ( format ! (
70
79
"https://example.com/{}" ,
@@ -86,7 +95,6 @@ fn generate_lock_file(path: &str) {
86
95
let mut config = Config :: default ( ) . with_cache_dir ( cache_dir. path ( ) . to_owned ( ) ) ;
87
96
88
97
let _git_dir = set_up_git_repos ( & mut config) ;
89
- dbg ! ( _git_dir. into_path( ) ) ;
90
98
91
99
// Make an empty git repo as the index.
92
100
Command :: new ( "git" )
0 commit comments