From 3c30ff02fb27cd3fd50a31a64fd273ec07c6d9b2 Mon Sep 17 00:00:00 2001 From: Greg Nazario Date: Tue, 22 Oct 2024 16:13:45 -0400 Subject: [PATCH] [cli] Add .gitignore in new move folders and in .aptos folder (#15024) --- crates/aptos/src/common/types.rs | 12 ++++++++++++ crates/aptos/src/move_tool/mod.rs | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/aptos/src/common/types.rs b/crates/aptos/src/common/types.rs index 0b5fc13047670..f0bccd29ea845 100644 --- a/crates/aptos/src/common/types.rs +++ b/crates/aptos/src/common/types.rs @@ -73,6 +73,7 @@ const US_IN_SECS: u64 = 1_000_000; const ACCEPTED_CLOCK_SKEW_US: u64 = 5 * US_IN_SECS; pub const DEFAULT_EXPIRATION_SECS: u64 = 30; pub const DEFAULT_PROFILE: &str = "default"; +pub const GIT_IGNORE: &str = ".gitignore"; // Custom header value to identify the client const X_APTOS_CLIENT_VALUE: &str = concat!("aptos-cli/", env!("CARGO_PKG_VERSION")); @@ -374,8 +375,19 @@ impl CliConfig { let aptos_folder = Self::aptos_folder(ConfigSearchMode::CurrentDir)?; // Create if it doesn't exist + let no_dir = !aptos_folder.exists(); create_dir_if_not_exist(aptos_folder.as_path())?; + // If the `.aptos/` doesn't exist, we'll add a .gitignore in it to ignore the config file + // so people don't save their credentials... + if no_dir { + write_to_user_only_file( + aptos_folder.join(GIT_IGNORE).as_path(), + GIT_IGNORE, + "*\ntestnet/\nconfig.yaml".as_bytes(), + )?; + } + // Save over previous config file let config_file = aptos_folder.join(CONFIG_FILE); let config_bytes = serde_yaml::to_string(&self).map_err(|err| { diff --git a/crates/aptos/src/move_tool/mod.rs b/crates/aptos/src/move_tool/mod.rs index 74e2eaaa5eb1a..e9dabe23e3968 100644 --- a/crates/aptos/src/move_tool/mod.rs +++ b/crates/aptos/src/move_tool/mod.rs @@ -10,7 +10,7 @@ use crate::{ CliTypedResult, ConfigSearchMode, EntryFunctionArguments, EntryFunctionArgumentsJSON, MoveManifestAccountWrapper, MovePackageDir, OptimizationLevel, OverrideSizeCheckOption, ProfileOptions, PromptOptions, RestOptions, SaveFile, ScriptFunctionArguments, - TransactionOptions, TransactionSummary, + TransactionOptions, TransactionSummary, GIT_IGNORE, }, utils::{ check_if_file_exists, create_dir_if_not_exist, dir_default_to_current, @@ -270,6 +270,15 @@ impl FrameworkPackageArgs { toml::to_string_pretty(&manifest) .map_err(|err| CliError::UnexpectedError(err.to_string()))? .as_bytes(), + )?; + + // Write a .gitignore + let gitignore = package_dir.join(GIT_IGNORE); + check_if_file_exists(gitignore.as_path(), prompt_options)?; + write_to_file( + gitignore.as_path(), + GIT_IGNORE, + ".aptos/\nbuild/".as_bytes(), ) } }