Class: GitBlur::Actions
- Inherits:
-
Object
- Object
- GitBlur::Actions
- Defined in:
- lib/git-blur/actions.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #diff(file_path) ⇒ Object
- #init ⇒ Object
-
#initialize(new_repo = false, repo_dir = false) ⇒ Actions
constructor
A new instance of Actions.
- #smudge ⇒ Object
Constructor Details
#initialize(new_repo = false, repo_dir = false) ⇒ Actions
Returns a new instance of Actions.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/git-blur/actions.rb', line 9 def initialize( new_repo = false, repo_dir = false ) if repo_dir Dir.chdir( repo_dir ) end status, out = exec( "git rev-parse --show-cdup 2>/dev/null" ) raise "#{Dir.pwd} does not seem to be a git repo" if status != 0 @repo_dir = File.join( Dir.pwd, out ) @conf_file = File.join( @repo_dir, ".git", "blur.conf" ) if new_repo status, out = exec( "git status -uno --porcelain" ) raise "Can't retrieve repo status" if status != 0 raise "Your repo is dirty. Please commit or stash your changes" if out.length > 0 end GitBlur::Conf.read_configuration( @conf_file ) if not new_repo end |
Instance Method Details
#clean ⇒ Object
58 59 60 61 62 |
# File 'lib/git-blur/actions.rb', line 58 def clean #STDIN -> encrypt -> STDOUT cm = GitBlur::Crypto::CipherMgr.new cm.encrypt_stream( $stdin ) end |
#diff(file_path) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/git-blur/actions.rb', line 71 def diff( file_path ) cm = GitBlur::Crypto::CipherMgr.new File.open( file_path ) do |f| cm.decrypt_stream( f ) end end |
#init ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/git-blur/actions.rb', line 29 def init raise "Configuration file #{@conf_file} already exists. I won't overwrite it :)" if File.file? @conf_file GitBlur::Conf.ciphers = [ 'aes-256-cbc', 'bf-cbc', 'des-ede3-cbc' ] kg = GitBlur::KeyGen.get_key_generators[ 'password' ].new kg.generate_keys GitBlur::Conf.store_keys_from_gen( kg ) #Configure filters status, out = exec( "git config filter.git-blur.smudge 'git-blur smudge'" ) raise "Git config failed" if status != 0 status, out = exec( "git config filter.git-blur.clean 'git-blur clean'" ) raise "Git config failed" if status != 0 status, out = exec( "git config diff.git-blur.textconv 'git-blur diff'" ) raise "Git config failed" if status != 0 puts "Storing configuration file in #{@conf_file}" GitBlur::Conf.write_configuration( @conf_file ) status, out = exec( "git rev-parse HEAD >/dev/null 2>/dev/null" ) if status == 0 puts "Checking out HEAD to decrypt any stored file" status, out = exec( "git checkout -f HEAD -- #{@repo_dir}" ) raise "Git checkout failed" if status != 0 end end |