Skip to content

Commit

Permalink
[cli] Add .gitignore in new move folders and in .aptos folder (#15024)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored Oct 22, 2024
1 parent c9315e3 commit 3c30ff0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions crates/aptos/src/common/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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| {
Expand Down
11 changes: 10 additions & 1 deletion crates/aptos/src/move_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
)
}
}
Expand Down

0 comments on commit 3c30ff0

Please sign in to comment.