Class: FossGit

Inherits:
Object
  • Object
show all
Defined in:
lib/fossgit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checkout_path = '') ⇒ FossGit

Returns a new instance of FossGit.



5
6
7
8
9
10
# File 'lib/fossgit.rb', line 5

def initialize checkout_path=''
  @checkout_path = checkout_path
  @checkout_path = get_element_matching :'local-root'

  @fossil_repository = get_repository_path
end

Instance Attribute Details

#checkout_pathObject (readonly)

Returns the value of attribute checkout_path.



2
3
4
# File 'lib/fossgit.rb', line 2

def checkout_path
  @checkout_path
end

#fossil_repositoryObject (readonly)

Returns the value of attribute fossil_repository.



3
4
5
# File 'lib/fossgit.rb', line 3

def fossil_repository
  @fossil_repository
end

Class Method Details

.versionObject



12
13
14
# File 'lib/fossgit.rb', line 12

def self.version
  '1.1.0'
end

Instance Method Details

#fossil_commandObject



24
25
26
27
28
29
30
31
32
# File 'lib/fossgit.rb', line 24

def fossil_command
  cmd = ['fossil export --git']

  cmd << "--import-marks #{fossil_marks}" if update_export?
  cmd << "--export-marks #{fossil_marks}"
  cmd << fossil_repository

  cmd.join ' '
end

#fossil_marksObject



16
17
18
# File 'lib/fossgit.rb', line 16

def fossil_marks
  File.join checkout_path, 'fossil.marks'
end

#git_commandObject



38
39
40
41
42
43
44
45
# File 'lib/fossgit.rb', line 38

def git_command
  cmd = ['git fast-import']

  cmd << "--import-marks=#{git_marks}" if update_export?
  cmd << "--export-marks=#{git_marks}"

  cmd.join ' '
end

#git_marksObject



20
21
22
# File 'lib/fossgit.rb', line 20

def git_marks
  File.join checkout_path, 'git.marks'
end

#git_remotes(gitpath) ⇒ Object



74
75
76
77
78
# File 'lib/fossgit.rb', line 74

def git_remotes gitpath
  Dir.chdir gitpath do
    `git remote`.split "\n"
  end
end

#mirror_commandObject



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

def mirror_command
  [fossil_command, sed_command, git_command].join '|'
end

#push_command(gitremote) ⇒ Object



34
35
36
# File 'lib/fossgit.rb', line 34

def push_command gitremote
  "; git checkout trunk; git push #{gitremote} trunk"
end

#push_mirror_command(gitremote) ⇒ Object



55
56
57
# File 'lib/fossgit.rb', line 55

def push_mirror_command gitremote
  mirror_command + push_command(gitremote)
end

#push_remote_list!(remote_list) ⇒ Object



59
60
61
62
63
64
# File 'lib/fossgit.rb', line 59

def push_remote_list! remote_list
  remote_list.each do |gitremote|
    puts "PUSH TO: #{gitremote}"
    system push_mirror_command(gitremote)
  end
end

#sed_commandObject



47
48
49
# File 'lib/fossgit.rb', line 47

def sed_command
  %q{sed 's/^\(committer \+\)\([^ ]\+@[^ ]\+\)\( *<\)\(\w\+\)\(>.*\)$/\1\4\3\2\5/'}
end

#text_export_commandObject



66
67
68
# File 'lib/fossgit.rb', line 66

def text_export_command
  [fossil_command, sed_command].join '|'
end

#update_export?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/fossgit.rb', line 70

def update_export?
  File.exist? git_marks and File.exist? fossil_marks
end