lib/braid/operations.rb in dreamcat4-braid-0.53 vs lib/braid/operations.rb in dreamcat4-braid-0.531
- old
+ new
@@ -135,72 +135,83 @@
def verbose?
Braid.verbose
end
end
- class GitClone < Proxy
+ class GitClone
+
+ include Singleton
+
def in_rep_root_check
if ! File.exists?(".git")
raise("Not in root repository.")
end
end
-
+
def add_gitignore(path)
- # add mirror to .gitignore file
+ # remove mirror from .gitignore file
in_rep_root_check
- if ! File.exists?(".gitignore")
- f = File.new(".gitignore", "w+")
- else
- f = File.open( 'index', 'w+')
+ if File.exists?(".gitignore")
+ f = File.open( '.gitignore', 'r+')
+ path_ignored = nil
+ f.each { |line|
+ if line == path+"\n"
+ path_ignored = line
+ end
+ }
+ f.rewind
+ f.close
+
+ if ! path_ignored
+ date_str = Date.new.to_s
+ f = File.open( '.gitignore', 'r+')
+ n = File.new(".gitignore-#{date_str}", "w+")
+ f.each { |line| n.puts line }
+ n.puts path+"\n"
+ n.close
+ f.close
+ File.rename( ".gitignore-#{date_str}", ".gitignore" )
+ Git.instance.add(".gitignore")
+ end
end
-
- f.each { |line|
- if line == path
- path_ignored = line
- end
- }
- if ! ignored
- f.puts path
- git.add(".gitignore")
- end
- f.close
end
def remove_gitignore(path)
# remove mirror from .gitignore file
in_rep_root_check
if File.exists?(".gitignore")
- f = File.open( 'index', 'w+')
-
+ f = File.open( '.gitignore', 'r+')
+ path_ignored = nil
f.each { |line|
- if line == path
+ if line == path+"\n"
path_ignored = line
end
}
f.rewind
-
+ f.close
+
if path_ignored
date_str= Date.new.to_s
+ f = File.open( '.gitignore', 'r+')
n = File.new(".gitignore-#{date_str}", "w+")
f.each { |line|
n.puts line unless line == path_ignored
}
n.close
+ f.close
+ File.rename( ".gitignore-#{date_str}", ".gitignore" )
+ Git.instance.add(".gitignore")
end
- f.close
- File.rename( ".gitignore-#{date_str}", ".gitignore" )
- git.add(".gitignore")
end
-
end
private
def command(name)
"#{self.class.command} #{name}"
end
- def git
+ def gitclone
GitClone.instance
end
end
class Git < Proxy
@@ -434,9 +445,13 @@
Git.instance
end
end
module VersionControl
+ def gitclone
+ GitClone.instance
+ end
+
def git
Git.instance
end
def git_svn