27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/github/cli.rb', line 27
def rename_default_branch(*args, options)
token = options[:token]
repo_path = options[:repo] || ""
_assert_not_nil_repo(repo_path)
old_branch = args[0] || "master"
new_branch = args[1] || "main"
if old_branch == new_branch
logger.error "Branch #{branch} is the same as #{based_on_branch}"
exit 1
end
_rename_prompt(repo_path, token, old_branch, new_branch)
repo = Github::RepoX.new(token, repo_path)
old_branch_sha = repo.branch_sha(old_branch)
logger.debug "Creating branch #{new_branch} based on #{old_branch}."
repo.create_branch(new_branch, old_branch_sha) {
_delete_branch_prompt(repo_path, token, new_branch)
logger.debug "Deleting branch #{new_branch}."
repo.delete_branch(new_branch)
}
logger.debug "Setting #{new_branch} as default branch."
repo.set_default_branch(new_branch)
logger.debug "Deleting #{old_branch}."
repo.delete_branch(old_branch)
if new_branch == "main"
global_default_branch = `git config --global init.defaultBranch`.strip
if global_default_branch != new_branch
`git config --global init.defaultBranch #{new_branch}`
logger.debug "Setting #{new_branch} as global default branch."
end
end
logger.info "Finished."
end
|