Module: GGSM::Delete

Includes:
Stash, Submodule
Included in:
Cli
Defined in:
lib/ggsm/command/delete.rb

Instance Method Summary collapse

Methods included from Stash

#stash_pop, #try_stash

Methods included from Submodule

#check_submodule, #check_submodule_status, #check_un_commit_code, #correct_dir, #foreach_module, #get_current_branch, #get_head_commit, #get_lastest_msg, #get_lastest_msg_not_merge, #get_lastest_msg_of_module, #get_modified_submodule, #get_submodule, #get_submodule_commit, #is_submodule, #tip_contact_author

Methods included from Hooks

#check_hooks, #cp_files, #cp_hooks, #install_billow, #update_hooks

Instance Method Details

#delete_branch(all, branch, remote) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ggsm/command/delete.rb', line 21

def delete_branch(all, branch, remote)
  if branch == get_current_branch
    puts "无法删除当前所在分支:#{branch},请switch其他分支后再执行\"ggsm delete\"".red
    exit 0
  end

  if all
    delete_local_branch(branch)
    delete_remote_branch(branch)
  elsif remote
    delete_remote_branch(branch)
  else
    delete_local_branch(branch)
  end
end

#delete_flow(branch, remote, all) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ggsm/command/delete.rb', line 9

def delete_flow(branch, remote, all)
  check_submodule

  puts '==> 进入主工程:'.yellow

  delete_branch(all, branch, remote)

  foreach_module {
    delete_branch(all, branch, remote)
  }
end

#delete_local_branch(branch) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/ggsm/command/delete.rb', line 37

def delete_local_branch(branch)
  if `git branch | grep -e '\s|*#{branch}$'`.strip == ''
    puts "warning: branch '#{branch}' not found"
  else
    info = `git branch -D #{branch}`
    if info.strip != ''
      puts "#{info}"
    end
  end
end

#delete_remote_branch(branch) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/ggsm/command/delete.rb', line 48

def delete_remote_branch(branch)
  if `git branch -r | grep -e '\s|*origin/#{branch}$'`.strip == ''
    puts "warning: remote branch '#{branch}' not found"
  else
    system "git push origin -d #{branch}"
    `git fetch -p origin`
  end
end