Class: Worktree::Command::Init
- Inherits:
-
Object
- Object
- Worktree::Command::Init
- Defined in:
- lib/worktree/command/init.rb
Instance Method Summary collapse
- #do! ⇒ Object
-
#initialize(uri, repo_path:) ⇒ Init
constructor
A new instance of Init.
Constructor Details
#initialize(uri, repo_path:) ⇒ Init
Returns a new instance of Init.
8 9 10 11 |
# File 'lib/worktree/command/init.rb', line 8 def initialize(uri, repo_path:) @uri = uri @repo_path = File. repo_path end |
Instance Method Details
#do! ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/worktree/command/init.rb', line 13 def do! # clone git repo @git = Git.clone(@uri, tmp_repo_name, path: @repo_path) # rearrange repo folders FileUtils.mkdir_p "#{@repo_path}/#{repo_name}" git_master_path = "#{@repo_path}/#{repo_name}/master" FileUtils.mv "#{@repo_path}/#{tmp_repo_name}", git_master_path # reinit git from new path @git = Worktree.git_for(git_master_path) remote_name = TTY::Prompt.new.ask?('What is remote name?', default: 'origin') unless remote_name == 'origin' # add remote @git.add_remote remote_name, @uri # TODO: remove origin remote? end end |