Class: Bruw::Commands::Git

Inherits:
Thor
  • Object
show all
Defined in:
lib/bruw/commands/git.rb

Instance Method Summary collapse

Instance Method Details

#add_remote(repository) ⇒ Object



87
88
89
90
91
92
93
94
95
96
# File 'lib/bruw/commands/git.rb', line 87

def add_remote(repository)
  prompt = TTY::Prompt.new
  path = "#{options[:owner]}/#{repository}"
  return unless prompt.yes?("Adding remote #{repository} linked to repository : https://github.com/#{path}")

  `git remote add #{repository} [email protected]:#{path}.git`
  puts "Remote #{repository.colorize(:green)} successfully created"
rescue StandardError => e
  puts e.message.colorize(:red)
end

#add_remotes(owner = "OpenSourcePolitics") ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bruw/commands/git.rb', line 42

def add_remotes(owner = "OpenSourcePolitics")
  unless Bruw::Git.cmd_exists?("gh")
    raise StandardError, "Please install Github CLI for using this command

You can install it using brew

`brew install gh` or upgrade `brew upgrade gh`

This command needs at least v1.7.0 for command repo list (https://github.com/cli/cli/releases/tag/v1.7.0)
Official repository : https://github.com/cli/cli"
  end
  prompt = TTY::Prompt.new

  remotes = Bruw::Git.repos(owner, options[:pattern], options[:without])

  remotes = prompt.multi_select("Select the git remote you want to add", remotes) unless options[:all]

  remotes.each do |remote|
    `git remote add #{remote} [email protected]:#{owner}/#{remote}.git`
  end
rescue StandardError => e
  puts e.message.colorize(:red)
end

#branch(remote, branch) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/bruw/commands/git.rb', line 72

def branch(remote, branch)
  raise StandardError, "You have uncommitted work, please commit or stash work before" if Bruw::Git.local_changes?
  raise StandardError, "Not in git repository" unless Bruw::Git.git?

  Bruw::Git.fetch(remote)
  puts Bruw::Git.branch(remote, branch)
rescue StandardError => e
  puts e.message.colorize(:red)
end

#open(remote = "origin") ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/bruw/commands/git.rb', line 14

def open(remote = "origin")
  raise StandardError, "Not in git repository" unless Bruw::Git.git?

  path = Bruw::Git.find_path(remote)

  current_branch = `git branch --show-current`
  `open https://github.com/#{path}/tree/#{current_branch}`
rescue StandardError => e
  puts e.message.colorize(:red)
end

#prune(pattern = "decidim-") ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/bruw/commands/git.rb', line 107

def prune(pattern = "decidim-")
  prompt = TTY::Prompt.new

  remotes = Bruw::Git.remotes(pattern)

  raise StandardError, "No git remotes to remove" unless remotes.count.positive?

  if options[:interactive]
    remotes = prompt.multi_select("Select the git remote to remove", remotes)
  else
    puts "Found remotes :"
    puts remotes
  end

  raise StandardError, "bruw decidim prune canceled" unless prompt.yes?("Do you really want to prune #{remotes.count.to_s.colorize(:green)} remotes ?")

  Bruw::Git.prune_remotes(remotes)
  puts "Remotes successfully removed !".colorize(:green)
rescue StandardError => e
  puts e.message.colorize(:red)
end

#remotesObject



29
30
31
32
33
# File 'lib/bruw/commands/git.rb', line 29

def remotes
  puts Bruw::Git.remotes
rescue StandardError => e
  puts e.message.colorize(:red)
end