Module: Waggit

Defined in:
lib/waggit.rb

Class Method Summary collapse

Class Method Details

.clean(options = {}) ⇒ Object



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

def self.clean(options={})
  dir = get_waggit_dir
  if dir
    Dir.chdir(dir) do 
      Files.clean_css
    end
  end
end

.confirm_pushObject

Since pushing local content can overwrite remote content we want the user to confirm the operation



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/waggit.rb', line 184

def self.confirm_push()
  puts "Performing this operation will overwrite content on the server."
  response = nil
  while response.nil?
    puts "Do you want to continue? [y/n]"
    response = $stdin.gets.chomp.downcase
    case response
    when "y", "yes"
      return true
    when "n", "no"
      return false
    else
      puts "Invalid response! Plese try again."
      response = nil
    end
  end
end

.forcepush(options) ⇒ Object

Push local changes to wagon, ignoring git.



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/waggit.rb', line 54

def self.forcepush(options)
  if confirm_push
    dir = get_waggit_dir
    if dir
      Dir.chdir(dir) do 
        Files.clean_css
        Wagon.push(options)
      end
    end
  end
end

.get_waggit_dirObject

Waggit can only really work if it is in a directory that has both git and wagon setup. This finds an appropriate working directory with both waggit and git and return the path as a string or return nil.



33
34
35
36
37
38
39
40
41
# File 'lib/waggit.rb', line 33

def self.get_waggit_dir()
  dir = Wagon.get_wagon_path
  puts "error: Unable to find a Wagon directory in your current path." unless dir
  if dir
    dir = Git.is_git_dir?(dir) ? dir : nil
    puts "error: Wagon directory is not setup with git: #{dir}" unless dir
  end
  return dir
end

.pull(options) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/waggit.rb', line 88

def self.pull(options)
  dir = get_waggit_dir
  if dir
    Dir.chdir(dir) do 
      begin
        Git.checkout_master
        Git.delete_wagon
        Git.delete_local
        Git.stash

        Git.checkout_new_wagon
        Wagon.pull(options)
        #TODO: Checkout: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
        if Git.has_changes?
          Git.add_all
          Git.commit "merge wagon pull"
        end

        Git.checkout_master
        Git.rebase_wagon
        Git.checkout_master
        Git.merge_wagon

        Git.checkout_new_local
        Git.stash_pop
        Git.add_all
        Git.commit_prompt
        Git.rebase_local
        Git.checkout_master
        Git.merge_local
        Git.delete_wagon
        Git.delete_local
    	rescue Exception
        puts "Pull aborted, switching back to master branch"
        Git.checkout_master
        raise
      end
    end
  end
end

.push(options) ⇒ Object

Commit local changes and keep in sync with git, then push to wagon.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/waggit.rb', line 68

def self.push(options)
  if confirm_push
    dir = get_waggit_dir
    if dir
      Dir.chdir(dir) do 
        Git.add_all
        Git.commit_prompt
        Files.clean_css
        if Git.has_changes?
          Git.add_all
          Git.commit "cleaned css"
        end
        Git.pull
        Git.push
        Wagon.push(options)
      end
    end
  end
end

.sync(options) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/waggit.rb', line 129

def self.sync(options)
  dir = get_waggit_dir
  if dir
    Dir.chdir(dir) do 
      begin
        Git.checkout_master
        Git.delete_wagon
        Git.delete_local
        Git.stash

        Git.checkout_new_wagon
        Wagon.pull(options)
        #TODO: Checkout: http://stackoverflow.com/questions/3515597/git-add-only-non-whitespace-changes
        if Git.has_changes?
          Git.add_all
          Git.commit "merge wagon pull"
        end

        Git.checkout_master
        Git.rebase_wagon
        Git.checkout_master
        Git.merge_wagon

        Git.checkout_new_local
        Git.stash_pop
        Git.add_all
        Git.commit_prompt
        Git.rebase_local
        Git.checkout_master
        Git.merge_local
        Git.delete_wagon
        Git.delete_local

        Files.clean_css
        if Git.has_changes?
          Git.add_all
          Git.commit "cleaned css"
        end

        Git.pull
        Git.push

        Wagon.push(options)
      rescue Exception
        puts "Sync aborted, switching back to master branch"
        Git.checkout_master
        raise
      end
    end
  end
end

.test_dir(options = {}) ⇒ Object

Verifies that the current working directory is setup to work with both git and wagon



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/waggit.rb', line 9

def self.test_dir(options={})
  test = true
  if !Git.is_git_dir?
    # FIXME: Cannot find a way to capture the output of the above git method, 
    # so there is another error that is output: 'fatal: Not a git repository 
    # (or any of the parent directories): .git'

    #puts "error: not in a git directory."
    test = false
  end 
  if !Wagon.is_wagon_dir?
    puts "error: Not in a wagon directory."
    test = false
  end 
  if test
    puts "Current directory is both a wagon and a git directory"
  end
  return test
end