Class: Dev::Template::Git

Inherits:
BaseInterface show all
Defined in:
lib/firespring_dev_commands/templates/git.rb

Overview

Class contains rake templates for managing your git project

Instance Attribute Summary

Attributes inherited from BaseInterface

#exclude

Instance Method Summary collapse

Methods inherited from BaseInterface

#create_tasks!, #initialize

Constructor Details

This class inherits a constructor from Dev::Template::BaseInterface

Instance Method Details

#create_checkout_task!Object

Create the rake task for the git checkout method



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/firespring_dev_commands/templates/git.rb', line 8

def create_checkout_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :git do
      return if exclude.include?(:checkout)

      desc 'Checks out a branch for each repo (alias: git:co)' \
           "\n\tuse BRANCH=abc123 to specify the branch of code you with to switch to (required)" \
           "\n\tIf the branch does not exist, the configured staging or main branch will be checked out"
      task checkout: %w(init) do
        branch = ENV['BRANCH'].to_s.strip
        raise 'branch is required' if branch.empty?

        Dev::Git.new.checkout_all(branch)
      end

      task co: %w(init checkout) do
        # This is an alias to the checkout command
      end

      d = Dev::Git.new
      [d.main_branch, d.staging_branch].uniq.each do |it|
        desc "Checks out the #{it} branch for each repo (alias: git:co:#{it})"
        task "checkout:#{it}": %w(init) do
          Dev::Git.new.checkout_all(it)
        end

        task "co:#{it}": %W(init checkout:#{it}) do
          # This is an alias to the checkout command
        end
      end
    end
  end
end

#create_merge_task!Object

Create the rake task for the git merge method



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/firespring_dev_commands/templates/git.rb', line 118

def create_merge_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :git do
      return if exclude.include?(:merge)

      desc 'Perform a "git merge" on each repo' \
           "\n\tuse BRANCH=abc123 to specify the branch of code you with to switch to (required)"
      task merge: %w(init) do
        branch = ENV['BRANCH'].to_s.strip
        raise 'branch is required' if branch.empty?

        Dev::Git.new.merge_all(branch)
      end

      d = Dev::Git.new
      [d.main_branch, d.staging_branch].uniq.each do |it|
        desc "Merge the #{it} branch into each repo"
        task "merge:#{it}": %w(init) do
          Dev::Git.new.merge_all(it)
        end
      end
    end
  end
end

#create_pull_task!Object

Create the rake task for the git pull method



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/firespring_dev_commands/templates/git.rb', line 46

def create_pull_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :git do
      return if exclude.include?(:pull)

      desc 'Pulls the latest for each repo'
      task pull: %w(init) do
        Dev::Git.new.pull_all
      end
    end
  end
end

#create_push_task!Object

Create the rake task for the git push method



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/firespring_dev_commands/templates/git.rb', line 63

def create_push_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :git do
      return if exclude.include?(:push)

      desc 'Pushes the current branch to origin'
      task push: %w(init) do
        Dev::Git.new.push_all
      end
    end
  end
end

#create_reset_task!Object

Create the rake task for the git reset method



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/firespring_dev_commands/templates/git.rb', line 80

def create_reset_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :git do
      return if exclude.include?(:reset)

      desc 'Performs a git reset in each repo'
      task reset: %w(init) do
        Dev::Git.new.reset_all
      end
    end
  end
end

#create_status_task!Object

Create the rake task for the git status method



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/firespring_dev_commands/templates/git.rb', line 97

def create_status_task!
  # Have to set a local variable to be accessible inside of the instance_eval block
  exclude = @exclude

  DEV_COMMANDS_TOP_LEVEL.instance_eval do
    namespace :git do
      return if exclude.include?(:status)

      desc 'Perform a "git status" on each repo (alias: git:st)'
      task status: %w(init) do
        Dev::Git.new.status_all
      end

      task st: %w(init status) do
        # This is an alias to the status command
      end
    end
  end
end