From b66e9fb526df3ef219b5a6b748bd4f644abb8fc1 Mon Sep 17 00:00:00 2001 From: sani haq Date: Sun, 25 Dec 2022 01:33:47 +0530 Subject: [PATCH 1/4] added .gitignore file --- sea-orm-cli/template/migration/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 sea-orm-cli/template/migration/.gitignore diff --git a/sea-orm-cli/template/migration/.gitignore b/sea-orm-cli/template/migration/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/sea-orm-cli/template/migration/.gitignore @@ -0,0 +1 @@ +/target From d25e5fcfa4e284d8f10c9acb847b15a04c7c95b9 Mon Sep 17 00:00:00 2001 From: sani haq Date: Sun, 25 Dec 2022 01:36:01 +0530 Subject: [PATCH 2/4] add .gitignore --- sea-orm-cli/src/commands/migrate.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/sea-orm-cli/src/commands/migrate.rs b/sea-orm-cli/src/commands/migrate.rs index c7fbaea5c..07567d00d 100644 --- a/sea-orm-cli/src/commands/migrate.rs +++ b/sea-orm-cli/src/commands/migrate.rs @@ -99,6 +99,7 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { write_file!("src/lib.rs"); write_file!("src/m20220101_000001_create_table.rs"); write_file!("src/main.rs"); + write_file!("src/.gitignore"); write_file!("Cargo.toml", "_Cargo.toml", |content: String| { let ver = format!( "{}.{}.0", From c136ecdde96d3b4ce21be6663cfd0230640cf88b Mon Sep 17 00:00:00 2001 From: sani haq Date: Fri, 30 Dec 2022 22:43:57 +0530 Subject: [PATCH 3/4] only add .gitignore if not in a existing git repo --- sea-orm-cli/Cargo.toml | 1 + sea-orm-cli/src/commands/migrate.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index 547f23c02..a8fb2e059 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -42,6 +42,7 @@ tracing = { version = "0.1", default-features = false } url = { version = "2.2", default-features = false } chrono = { version = "0.4.20", default-features = false, features = ["clock"] } regex = { version = "1", default-features = false } +git-discover = "0.10.0" [dev-dependencies] smol = "1.2.5" diff --git a/sea-orm-cli/src/commands/migrate.rs b/sea-orm-cli/src/commands/migrate.rs index 07567d00d..639dcda90 100644 --- a/sea-orm-cli/src/commands/migrate.rs +++ b/sea-orm-cli/src/commands/migrate.rs @@ -99,7 +99,9 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { write_file!("src/lib.rs"); write_file!("src/m20220101_000001_create_table.rs"); write_file!("src/main.rs"); - write_file!("src/.gitignore"); + if let Err(_) = git_discover::upwards(Path::new(&migration_dir)) { + write_file!("src/.gitignore"); + } write_file!("Cargo.toml", "_Cargo.toml", |content: String| { let ver = format!( "{}.{}.0", From 9e31aca04d4e4acd8c8823f0b19e6fd087ffeb54 Mon Sep 17 00:00:00 2001 From: Billy Chan Date: Wed, 22 Mar 2023 20:55:02 +0800 Subject: [PATCH 4/4] Use `git2` to detect git repository --- sea-orm-cli/Cargo.toml | 2 +- sea-orm-cli/src/commands/migrate.rs | 10 +++++++--- sea-orm-cli/template/migration/.gitignore | 1 - sea-orm-cli/template/migration/_gitignore | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 sea-orm-cli/template/migration/.gitignore create mode 100644 sea-orm-cli/template/migration/_gitignore diff --git a/sea-orm-cli/Cargo.toml b/sea-orm-cli/Cargo.toml index a8fb2e059..08a5472ba 100644 --- a/sea-orm-cli/Cargo.toml +++ b/sea-orm-cli/Cargo.toml @@ -42,7 +42,7 @@ tracing = { version = "0.1", default-features = false } url = { version = "2.2", default-features = false } chrono = { version = "0.4.20", default-features = false, features = ["clock"] } regex = { version = "1", default-features = false } -git-discover = "0.10.0" +git2 = { version = "0.16", default-features = false } [dev-dependencies] smol = "1.2.5" diff --git a/sea-orm-cli/src/commands/migrate.rs b/sea-orm-cli/src/commands/migrate.rs index 639dcda90..0b6cd5db3 100644 --- a/sea-orm-cli/src/commands/migrate.rs +++ b/sea-orm-cli/src/commands/migrate.rs @@ -84,6 +84,10 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { let fn_content = |content: String| content; write_file!($filename, $filename, fn_content); }; + ($filename: literal, $template: literal) => { + let fn_content = |content: String| content; + write_file!($filename, $template, fn_content); + }; ($filename: literal, $template: literal, $fn_content: expr) => { let filepath = [&migration_dir, $filename].join(""); println!("Creating file `{}`", filepath); @@ -99,9 +103,6 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { write_file!("src/lib.rs"); write_file!("src/m20220101_000001_create_table.rs"); write_file!("src/main.rs"); - if let Err(_) = git_discover::upwards(Path::new(&migration_dir)) { - write_file!("src/.gitignore"); - } write_file!("Cargo.toml", "_Cargo.toml", |content: String| { let ver = format!( "{}.{}.0", @@ -111,6 +112,9 @@ pub fn run_migrate_init(migration_dir: &str) -> Result<(), Box> { content.replace("", &ver) }); write_file!("README.md"); + if git2::Repository::discover(Path::new(&migration_dir)).is_ok() { + write_file!(".gitignore", "_gitignore"); + } println!("Done!"); Ok(()) diff --git a/sea-orm-cli/template/migration/.gitignore b/sea-orm-cli/template/migration/.gitignore deleted file mode 100644 index ea8c4bf7f..000000000 --- a/sea-orm-cli/template/migration/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/sea-orm-cli/template/migration/_gitignore b/sea-orm-cli/template/migration/_gitignore new file mode 100644 index 000000000..c41cc9e35 --- /dev/null +++ b/sea-orm-cli/template/migration/_gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file