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.



8
9
10
11
12
13
14
15
# File 'lib/fossgit.rb', line 8

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

  @fossil_repository = get_repository_path

  @project_name = get_project_name
end

Instance Attribute Details

#checkout_pathObject (readonly)

Returns the value of attribute checkout_path.



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

def checkout_path
  @checkout_path
end

#fossil_repositoryObject (readonly)

Returns the value of attribute fossil_repository.



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

def fossil_repository
  @fossil_repository
end

#project_nameObject

Returns the value of attribute project_name.



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

def project_name
  @project_name
end

Class Method Details

.versionObject



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

def self.version
  '1.2.0'
end

Instance Method Details

#fossil_commandObject



29
30
31
32
33
34
35
36
37
# File 'lib/fossgit.rb', line 29

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



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

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

#git_commandObject



43
44
45
46
47
48
49
50
# File 'lib/fossgit.rb', line 43

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



25
26
27
# File 'lib/fossgit.rb', line 25

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

#git_remotes(gitpath) ⇒ Object



80
81
82
83
84
# File 'lib/fossgit.rb', line 80

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

#mirror_commandObject



57
58
59
# File 'lib/fossgit.rb', line 57

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

#push_command(gitremote) ⇒ Object



39
40
41
# File 'lib/fossgit.rb', line 39

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

#push_mirror_command(gitremote) ⇒ Object



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

def push_mirror_command gitremote
  mirror_command + push_command(gitremote)
end

#push_remote_list!(remote_list) ⇒ Object



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

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

#sed_commandObject



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

def sed_command
  # legacy fix for a bug in an old Fossil version's Git-export
  %q{sed 's/^\(committer \+\)\([^ ]\+@[^ ]\+\)\( *<\)\(\w\+\)\(>.*\)$/\1\4\3\2\5/'}
end

#text_export_commandObject



72
73
74
# File 'lib/fossgit.rb', line 72

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

#update_export?Boolean

Returns:

  • (Boolean)


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

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