@@ -6,6 +6,10 @@ use josh_core::git::normalize_repo_path;
66#[ derive( Parser ) ]
77#[ command( about = "Josh Commit Queue" ) ]
88struct Cli {
9+ /// Path to the data directory (git repository). Defaults to current directory.
10+ #[ arg( long, global = true ) ]
11+ data_dir : Option < std:: path:: PathBuf > ,
12+
913 #[ command( subcommand) ]
1014 command : Commands ,
1115}
@@ -50,12 +54,17 @@ struct ServeArgs {
5054 port : u16 ,
5155}
5256
53- fn open_repo ( ) -> anyhow:: Result < (
57+ fn open_repo (
58+ data_dir : Option < & std:: path:: Path > ,
59+ ) -> anyhow:: Result < (
5460 std:: path:: PathBuf ,
5561 std:: sync:: Arc < josh_core:: cache:: CacheStack > ,
5662 josh_core:: cache:: Transaction ,
5763) > {
58- let repo = git2:: Repository :: open_from_env ( ) . context ( "Not in a git repository" ) ?;
64+ let repo = match data_dir {
65+ Some ( dir) => git2:: Repository :: open ( dir) . context ( "Failed to open git repository" ) ?,
66+ None => git2:: Repository :: open_from_env ( ) . context ( "Not in a git repository" ) ?,
67+ } ;
5968 let repo_path = normalize_repo_path ( repo. path ( ) ) ;
6069
6170 josh_core:: cache:: sled_load ( & repo_path. join ( ".git" ) ) . context ( "Failed to load sled cache" ) ?;
@@ -82,7 +91,7 @@ async fn main() -> anyhow::Result<()> {
8291 return Ok ( ( ) ) ;
8392 }
8493 Commands :: Serve ( args) => {
85- let ( repo_path, cache, _transaction) = open_repo ( ) ?;
94+ let ( repo_path, cache, _transaction) = open_repo ( cli . data_dir . as_deref ( ) ) ?;
8695
8796 let state = josh_cq:: cq:: AppState { repo_path, cache } ;
8897 let app = josh_cq:: cq:: make_router ( state) ;
@@ -94,7 +103,7 @@ async fn main() -> anyhow::Result<()> {
94103 axum:: serve ( listener, app) . await ?;
95104 }
96105 Commands :: Action ( action) => {
97- let ( _repo_path, _cache, transaction) = open_repo ( ) ?;
106+ let ( _repo_path, _cache, transaction) = open_repo ( cli . data_dir . as_deref ( ) ) ?;
98107
99108 match action {
100109 ActionCommands :: Track ( ref args) => {
0 commit comments