lib/git_cli/ignore.rb in git_cli-0.11.2 vs lib/git_cli/ignore.rb in git_cli-0.11.3
- old
+ new
@@ -18,13 +18,14 @@
module GitCli
module Ignore
def ignore(*val)
- with_ignore_file do |f|
+ with_ignore_file("a+") do |f|
+ cont = f.read
val.each do |v|
- f.puts v
+ f.puts(v) if (cont =~ /^#{v}\Z/) == nil
end
#f.puts val
end
log_debug ".gitignore file updated with line '#{val}'"
[true,".gitignore file updated"]
@@ -60,17 +61,18 @@
log_debug ".gitignore files is updated!"
[true,".gitignore file is updated"]
end
private
- def with_ignore_file(&block)
+ def with_ignore_file(mode = "a", &block)
+ mode = "a" if is_empty?(mode)
if block
st, root = workspace_root
root.strip!
if st
igPath = File.join(root,".gitignore")
FileUtils.touch(igPath) if not File.exist?(igPath)
- File.open(igPath,"a") do |f|
+ File.open(igPath,mode) do |f|
block.call(f)
end
else
raise GitCliException, "Cannot get workspace root. Probably not a GIT workspace?"
end