Class: TransparentGit::RemoteTracker

Inherits:
Object
  • Object
show all
Includes:
FromHash
Defined in:
lib/transparent_git/remote_tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/transparent_git/remote_tracker.rb', line 4

def name
  @name
end

#repo_holding_dirObject

Returns the value of attribute repo_holding_dir.



4
5
6
# File 'lib/transparent_git/remote_tracker.rb', line 4

def repo_holding_dir
  @repo_holding_dir
end

#working_dirObject

Returns the value of attribute working_dir.



4
5
6
# File 'lib/transparent_git/remote_tracker.rb', line 4

def working_dir
  @working_dir
end

Instance Method Details

#commit_current_state!Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/transparent_git/remote_tracker.rb', line 55

def commit_current_state!
  puts "doing #{working_dir}"

  existed = repo_exists?

  setup_env! do
    setup_repo!

    git "add -u"
    git "add ."
    eat_exceptions { git "commit -m \"Current State #{Time.now}\"" }

    #git "branch -m master transparent_git" unless !existed

    #puts "wait"
    #STDIN.gets

    #git "pull tg_origin master:master"
    #git "fetch tg_origin"
    #git "merge master tg_origin/master"

    #puts 'done'
  end
end

#create_repo!Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/transparent_git/remote_tracker.rb', line 28

def create_repo!
  FileUtils.mkdir_p(repo_holding_dir)
  if working_dir_repo? && false
    git :clone, working_dir.to_file_url,repo_dir,"--mirror"
    git :branch, :transparent_git

    git :remote, :add, :tg_origin, working_dir.to_file_url
    git :fetch, :tg_origin

    #git :checkout, :master
    #git "checkout transparent_git"

    File.create("#{repo_dir}/HEAD","ref: refs/heads/transparent_git")
  else
    git :init
  end
end

#delete_repo!Object



51
52
53
# File 'lib/transparent_git/remote_tracker.rb', line 51

def delete_repo!
  FileUtils.rm_r(repo_dir) if FileTest.exists?(repo_dir)
end

#repo_exists?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/transparent_git/remote_tracker.rb', line 13

def repo_exists?
  FileTest.exist? "#{repo_dir}/config"
end

#setup_env!Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/transparent_git/remote_tracker.rb', line 17

def setup_env!
  puts "setting env"
  ENV['GIT_DIR'] = repo_dir
  ENV['GIT_WORK_TREE'] = working_dir

  if block_given?
    yield
    ENV.delete('GIT_DIR')
    ENV.delete('GIT_WORK_TREE')
  end
end

#setup_repo!Object



45
46
47
48
49
50
# File 'lib/transparent_git/remote_tracker.rb', line 45

def setup_repo!
  create_repo! unless repo_exists?

  lock = "#{repo_dir}/refs/heads/master.lock"
  FileUtils.rm(lock) if FileTest.exist?(lock)
end

#working_dir_repo?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/transparent_git/remote_tracker.rb', line 10

def working_dir_repo?
  FileTest.exist? "#{working_dir}/.git"
end