Module: GitBackup

Defined in:
lib/git-backup.rb,
lib/git-backup/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.mainObject



4
5
6
7
8
9
10
11
12
# File 'lib/git-backup.rb', line 4

def self.main
  current_branch = `git rev-parse --abbrev-ref HEAD`.strip
  local_branches = `git branch`.delete(" ").split("\n")
  number_of_existing_backups = local_branches.count { |branch| branch =~ /backup\/#{Regexp.quote(current_branch)}-\d+/ }
  backup_branch_name = "backup/#{current_branch}-#{number_of_existing_backups + 1}"

  `git branch #{backup_branch_name}`
  puts "Created branch #{backup_branch_name}."
end