v init: create a .gitignore in existing git repo if it does not exist yet (#10488)

pull/10521/head
Ryan Roden-Corrent 2021-06-19 14:36:12 -04:00 committed by GitHub
parent 123682dffb
commit f0ad0b024e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 16 deletions

View File

@ -109,14 +109,14 @@ fn (c &Create) create_git_repo(dir string) {
cerror('Unable to create git repo')
exit(4)
}
if !os.exists('$dir/.gitignore') {
mut fl := os.create('$dir/.gitignore') or {
// We don't really need a .gitignore, it's just a nice-to-have
return
}
fl.write_string(gen_gitignore(c.name)) or { panic(err) }
fl.close()
}
if !os.exists('$dir/.gitignore') {
mut fl := os.create('$dir/.gitignore') or {
// We don't really need a .gitignore, it's just a nice-to-have
return
}
fl.write_string(gen_gitignore(c.name)) or { panic(err) }
fl.close()
}
}

View File

@ -2,15 +2,7 @@ import os
const test_path = 'vcreate_test'
fn test_v_init() ? {
dir := os.join_path(os.temp_dir(), test_path)
os.rmdir_all(dir) or {}
os.mkdir(dir) ?
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)
fn init_and_check() ? {
vexe := os.getenv('VEXE')
os.execute_or_panic('$vexe init')
@ -45,3 +37,43 @@ fn test_v_init() ? {
'',
].join('\n')
}
fn test_v_init() ? {
dir := os.join_path(os.temp_dir(), test_path)
os.rmdir_all(dir) or {}
os.mkdir(dir) ?
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)
init_and_check() ?
}
fn test_v_init_in_git_dir() ? {
dir := os.join_path(os.temp_dir(), test_path)
os.rmdir_all(dir) or {}
os.execute_or_panic('git init $dir')
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)
init_and_check() ?
}
fn test_v_init_no_overwrite_gitignore() ? {
dir := os.join_path(os.temp_dir(), test_path)
os.rmdir_all(dir) or {}
os.mkdir(dir) or {}
os.write_file('$dir/.gitignore', 'blah') ?
defer {
os.rmdir_all(dir) or {}
}
os.chdir(dir)
vexe := os.getenv('VEXE')
os.execute_or_panic('$vexe init')
assert os.read_file('.gitignore') ? == 'blah'
}