class Options
Public Class Methods
new()
click to toggle source
# File lib/g4tOptions.rb, line 2 def initialize @prompt = TTY::Prompt.new end
Public Instance Methods
add_files()
click to toggle source
# File lib/g4tOptions.rb, line 22 def add_files $lastmsg = "Now that we added the files" all_files = @prompt.yes?("Add all files?") if all_files cmd = "git add ." puts("Adding all files...") else fname = @prompt.ask("File to add:") cmd = "git add #{fname}" end run_command(cmd) end
change_branch()
click to toggle source
# File lib/g4tOptions.rb, line 93 def change_branch bname = @prompt.ask("Branch name:") run_command("git checkout -b #{bname}") end
clone_repo()
click to toggle source
# File lib/g4tOptions.rb, line 56 def clone_repo uname = @prompt.ask("Username:") repo = @prompt.ask("Repository name:") run_command("git clone https://github.com/#{uname}/#{repo}/") end
commit_files()
click to toggle source
# File lib/g4tOptions.rb, line 6 def commit_files $lastmsg = "Now that we commited the files" msg = @prompt.ask("Commit message:") if msg[0] != "\"" msg = "\"#{msg}" end if msg[-1] != "\"" msg = "#{msg}\"" end puts msg run_command("git commit -m #{msg}") end
diff()
click to toggle source
# File lib/g4tOptions.rb, line 89 def diff run_command("git diff") end
git_info()
click to toggle source
# File lib/g4tOptions.rb, line 98 def git_info status = { "Git branch" => IO.popen("git branch"), "Repository url" => IO.popen("git config --get remote.origin.url") } status.each do |k, v| puts("#{k}: #{v.read}") end puts("____________\n\n") end
hard_reset()
click to toggle source
# File lib/g4tOptions.rb, line 72 def hard_reset confirmation = @prompt.yes?("do you really want to hard reset?") if confirmation run_command("git reset --hard HEAD~") else puts "Cancelling operation" end end
initialize_git()
click to toggle source
# File lib/g4tOptions.rb, line 83 def initialize_git $lastmsg = "Now that we initialized .git" puts("Initializing Git repository in '#{Dir.pwd}/.git'...") run_command("git init") end
logs()
click to toggle source
# File lib/g4tOptions.rb, line 35 def logs run_command("git log") end
pull_changes()
click to toggle source
# File lib/g4tOptions.rb, line 118 def pull_changes git_pull_options = ["rebase", "no-rebase", "ff-only"] chose = @prompt.select("chose: ", git_pull_options) run_command("git pull --#{chose}") end
push_branch()
click to toggle source
# File lib/g4tOptions.rb, line 39 def push_branch branch = @prompt.ask("Branch to push:") run_command("git push origin #{branch}") end
remote_adress()
click to toggle source
# File lib/g4tOptions.rb, line 44 def remote_adress $lastmsg = "Now that we the remote address" uname = @prompt.ask("Your github username:") repo = @prompt.ask("Your repository name:") puts("Adding remote repository https://github.com/#{uname}/#{repo}...") run_command("git remote add origin https://github.com/#{uname}/#{repo}.git") end
remove_file()
click to toggle source
# File lib/g4tOptions.rb, line 109 def remove_file file_name = @prompt.ask("Enter the file name: ") run_command("git rm #{file_name}") end
reset()
click to toggle source
# File lib/g4tOptions.rb, line 67 def reset commit = @prompt.ask("Commit id:") run_command("git reset --hard #{commit}") end
restore()
click to toggle source
# File lib/g4tOptions.rb, line 62 def restore fname = @prompt.ask("File name:") run_command("git restore #{fname}") end
run_command(cmd)
click to toggle source
# File lib/g4tOptions.rb, line 124 def run_command(cmd) puts "Command: #{cmd}" system(cmd) end
show_last_commit()
click to toggle source
# File lib/g4tOptions.rb, line 114 def show_last_commit run_command("git show") end
status()
click to toggle source
# File lib/g4tOptions.rb, line 52 def status run_command("git status") end