Class: App::Git
Constant Summary collapse
- DELIMITER =
'*|*'
- SORT_DATE =
'date'
- SORT_REFNAME =
'refname'
- LOCAL =
'local'
- REMOTE =
'remote'
- CODE =
'code'
- DB =
'db'
- MERGED_PREFIX =
'MERGED-'
- MDASH =
"\xe2\x80\x94"
- MASTER =
'master'
- REFNAME =
'refname'
- OBJECT_TYPE =
'objecttype'
- OBJECT_SIZE =
'objectsize'
- OBJECT_NAME =
'objectname'
- TREE =
'tree'
- NUM_PARENT =
'numparent'
- COMMITTER_NAME =
'committername'
- COMMITTER_EMAIL =
'committeremail'
- COMMITTER_DATE =
'committerdate'
- SUBJECT =
'subject'
- UPSTREAM =
'upstream'
- BRANCH_NAME =
'branch_name'
- BRANCH_LOCATION =
'branch_location'
- BRANCH_EXISTS =
'branch_exists'
- BRANCH_EXISTS_LOCALLY =
'branch_exists_locally'
- BRANCH_IS_CURRENT =
'branch_is_current'
- BRANCH_IS_UP_TO_DATE =
'branch_is_up_to_date'
- BRANCH_HAS_STASH =
'branch_has_stash'
- BRANCH_HAS_UPSTREAM =
'branch_has_upstream'
- SAME_BRANCH_WARNING =
'same_branch_warning'
- SAME_BRANCH_ERROR =
'same_branch_error'
- RELEASE_BRANCH_REGEX =
/release-\d+\.\d+\.\d+-\d{4}/
- GIT_MERGE_DEFAULT_FILE =
'~/tmp/bp-merge.txt'
- GIT_LAST_GIT_FETCH_FILE =
'~/tmp/bp-last-git-fetch.tmp'
Instance Method Summary collapse
-
#ask_to_commit_to_git(commit_message, repo_dir, first_answer = nil, second_answer = nil) ⇒ Object
Shows prompts asking to ‘Commit to GIT’ and ‘Push to [master]’.
-
#ask_to_setup_remote_tracking(current_branch, repo_dir) ⇒ Object
Asks if you would like to setup remote tracking.
-
#branch_data(branch_name, code_db = nil, verbose = true) ⇒ Object
Returns an array that include info for BOTH repos.
-
#branch_exists(branch_name, repo_dir, local_remote = LOCAL) ⇒ Object
Returns TRUE if branch exists, FALSE if not.
-
#branch_exists_anywhere(branch_name, case_sensitive = false) ⇒ Object
Checks if branch exists ANYWHERE – Local, Remote, Code, DB.
- #branch_has_upstream(repo_dir, branch_name) ⇒ Object deprecated Deprecated.
-
#branch_is_up_to_date(repo_dir, branch_name) ⇒ Object
Checks if a branch is up-to-date with its remote.
- #branch_synced_with_upstream(repo_dir, branch_name) ⇒ Object deprecated Deprecated.
-
#changes_exist(repo_dir) ⇒ Object
Returns TRUE if changes exist or FALSE if there is nothing to commit.
-
#check_branch_does_not_exist_anywhere(branch_name) ⇒ Object
Checks that a branch DOESN’T exist anywhere (local, remote, code and db).
-
#check_branch_exists_somewhere(branch_name) ⇒ Object
Checks that a branch DOES exist somewhere (local, remote, code or db).
-
#check_for_conflicts(result, repo_dir, additional_info = nil) ⇒ Object
Pass the result of App::Terminal::command() and this should do the rest.
-
#check_for_same_branch(display = SAME_BRANCH_WARNING) ⇒ Object
Checks if both repos are on same branch and displays either ERROR or WARNING.
-
#check_for_stash(automatic = false) ⇒ Object
Checks if you currently have stashed changes for current branch and if so, prompt to un-stash them.
-
#check_for_stash_get_stashes(repo_dir) ⇒ Object
Sub-method for ‘show_branches’.
-
#check_for_uncommitted_files(automatic = false, force_stash_message = false) ⇒ Object
Checks if you have staged changes in current repo and if so, prompts to stash them.
-
#current_branch_for_repo(repo_dir) ⇒ Object
Get current branch for repo.
-
#get_all_branches_as_array ⇒ Object
Gets EVERY SINGLE BRANCH that exists – local & remote, code & db – and puts them in a single, unique, array.
-
#get_branches_as_array(local_remote = LOCAL, repo_dir = nil) ⇒ Object
Gets branch names as array.
-
#get_changed_files(repo_dir, branch_to_compare_to = "origin/#{App::Git::MASTER}") ⇒ Object
Get list of files that have changed between 2 branches.
-
#get_local_branches(sort = SORT_REFNAME, repo_dir = nil) ⇒ Object
Gets detailed info about local branches as Array.
-
#get_remote_branches(sort = SORT_REFNAME, repo_dir = nil) ⇒ Object
Gets detailed info about remote branches as Array.
-
#get_repo_shorthand(repo_dir) ⇒ Object
Returns short-hand string for repo.
-
#initialize ⇒ Git
constructor
A new instance of Git.
- #merge_master_into_current_branch(repo_dir, push_to_origin = true) ⇒ Object deprecated Deprecated.
-
#repo_loop ⇒ Object
Returns array with the paths to both repos.
-
#resolve_branch_for_jira(jira_number, ask_to_create = false) ⇒ Object
Resolves possible branch names from jira numbers (IE: BP-12345 from 12345).
-
#resolve_jira_for_branch(branch_name, exit_script = true) ⇒ Object
Resolves jira number from branch (IE: 12345 from BP-12345).
-
#show_branches(sort = SORT_REFNAME, local_remote = LOCAL) ⇒ Object
Outputs list of branches to terminal.
-
#show_branches_divider(column_width, color = 'white') ⇒ Object
Sub-method for ‘show_branches’.
-
#show_branches_draw_table(brightpearl_code, brightpearl_db) ⇒ Object
Draws the actual table of branches.
-
#show_branches_get_colors(code_branch, current_code_branch, current_db_branch, db_branch) ⇒ Object
Sub-method for ‘show_branches’.
-
#show_branches_get_db_branch(brightpearl_db, code_branch) ⇒ Object
Sub-method for ‘show_branches’.
-
#update_origin(repo_dir = nil) ⇒ Object
Updates origin (IE: remote branches).
-
#validate_code_db(code_db) ⇒ Object
Validates that a parameter is either ‘code’ or ‘db’.
-
#validate_local_remote(local_remote) ⇒ Object
Validates that a parameter is either ‘local’ or ‘remote’.
-
#validate_repo_dir(repo_dir) ⇒ Object
Makes sure the repo directory is valid.
-
#validate_sort(sort_option) ⇒ Object
Validates if sort option is supported.
- #verify_same_branch ⇒ Object deprecated Deprecated.
Constructor Details
#initialize ⇒ Git
Returns a new instance of Git.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/core/git.rb', line 54 def initialize @origin_updated_code = false @origin_updated_db = false @branch_upstream_data = false @branches_as_array = { :local_code => nil, :local_db => nil, :local_both => nil, :remote_code => nil, :remote_db => nil, :remote_both => nil } @branches_as_array_all = false end |
Instance Method Details
#ask_to_commit_to_git(commit_message, repo_dir, first_answer = nil, second_answer = nil) ⇒ Object
Shows prompts asking to ‘Commit to GIT’ and ‘Push to [master]’
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 |
# File 'lib/core/git.rb', line 871 def ask_to_commit_to_git(, repo_dir, first_answer = nil, second_answer = nil) if first_answer == App::Enum::NO App::Terminal::warning("Your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('committed')} to GIT.", 'You will need to do this manually.', false) else if first_answer == App::Enum::YES || App::Terminal::prompt_yes_no('Commit to GIT', ["This will commit your changes to GIT with message: #{App::Terminal::format_highlight()}"]) App::Terminal::command(["git commit -m '#{.gsub("'", "\\'")}'"], repo_dir) App::Terminal::info("Your changes have been #{App::Terminal::format_action('committed')} to GIT.") else App::Terminal::warning("Your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('committed')} to GIT.", 'You will need to do this manually.', false) return end end if second_answer == App::Enum::NO App::Terminal::warning("Your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('pushed')} to origin.", 'You will need to do this manually.', false) else if second_answer == App::Enum::YES || App::Terminal::prompt_yes_no('Push changes to origin') App::Terminal::command('git push', repo_dir) App::Terminal::info("Your changes have been #{App::Terminal::format_action('pushed')} to origin.") else App::Terminal::warning("Your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('pushed')} to origin.", 'You will need to do this manually.', false) end end end |
#ask_to_setup_remote_tracking(current_branch, repo_dir) ⇒ Object
Asks if you would like to setup remote tracking. WILL ASSUME that branch doesn’t have this (but won’t actually check).
792 793 794 795 796 797 798 799 800 801 802 803 |
# File 'lib/core/git.rb', line 792 def ask_to_setup_remote_tracking(current_branch, repo_dir) tracking_setup_command = "git branch --set-upstream-to=origin/#{current_branch} #{current_branch}" if App::Terminal::prompt_yes_no('Setup remote tracking?', ["No tracking information found for #{App::Terminal::format_branch(current_branch)} on #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}", "By continuing, the script will automatically setup your tracking information with: #{tracking_setup_command}"]) App::Terminal::output("Setting tracking information for this branch to origin/#{current_branch}") if !branch_exists(current_branch, repo_dir, App::Git::REMOTE) App::Terminal::command("git push -u origin #{current_branch}", repo_dir) end App::Terminal::command(tracking_setup_command, repo_dir) else App::Terminal::warning('No remote tracking setup', "You have not setup remote tracking for branch #{App::Terminal::format_branch(current_branch)}", false) end end |
#branch_data(branch_name, code_db = nil, verbose = true) ⇒ Object
Returns an array that include info for BOTH repos. Finds out whether a branch exists and if it’s current or not Only does it locally.
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/core/git.rb', line 636 def branch_data(branch_name, code_db = nil, verbose = true) data = [] repo_loop.each do |repo_dir| unless code_db.nil? validate_code_db(code_db) case code_db when CODE if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB) data << nil next end else if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) data << nil next end end end App::Terminal::output("Retrieving branch data for #{App::Terminal::format_branch(branch_name)} \xe2\x80\x94 (#{get_repo_shorthand(repo_dir)})") repo_data = {} repo_data repo_data[:"#{BRANCH_NAME}"] = branch_name repo_data[:"#{BRANCH_LOCATION}"] = repo_dir repo_data[:"#{BRANCH_EXISTS}"] = true repo_data[:"#{BRANCH_EXISTS_LOCALLY}"] = true repo_data[:"#{BRANCH_HAS_STASH}"] = false repo_data[:"#{BRANCH_HAS_UPSTREAM}"] = branch_has_upstream(repo_dir, branch_name) repo_data[:"#{BRANCH_IS_CURRENT}"] = (current_branch_for_repo(repo_dir) == branch_name ? true : false) if repo_data[:"#{BRANCH_HAS_UPSTREAM}"] # @todo repo_data[:"#{BRANCH_IS_UP_TO_DATE}"] = nil else # @todo repo_data[:"#{BRANCH_IS_UP_TO_DATE}"] = nil end # Check branch exists unless branch_exists(branch_name, repo_dir, App::Git::LOCAL) repo_data[:"#{BRANCH_EXISTS_LOCALLY}"] = false App::Terminal::output("Branch #{App::Terminal::format_branch(branch_name)} not found #{App::Terminal::format_action('locally')} in #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}", App::Terminal::MSG_WARNING) if verbose App::Terminal::output('Checking origin') if verbose unless branch_exists(branch_name, repo_dir, App::Git::REMOTE) App::Terminal::output("Branch #{App::Terminal::format_branch(branch_name)} not found #{App::Terminal::format_action('remotely')} in #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}", App::Terminal::MSG_WARNING) if verbose repo_data[:"#{BRANCH_EXISTS}"] = false data << repo_data next end end # Check for stashed changes stashes = `cd #{repo_dir} && git stash list | grep 'WIP on #{branch_name}:'` stashes = stashes.split("\n") if stashes.any? repo_data[:"#{BRANCH_HAS_STASH}"] = stashes.count end data << repo_data end data end |
#branch_exists(branch_name, repo_dir, local_remote = LOCAL) ⇒ Object
Returns TRUE if branch exists, FALSE if not
696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
# File 'lib/core/git.rb', line 696 def branch_exists(branch_name, repo_dir, local_remote = LOCAL) validate_repo_dir(repo_dir) validate_local_remote(local_remote) case local_remote when LOCAL branches = get_branches_as_array(LOCAL, repo_dir) else branches = get_branches_as_array(REMOTE, repo_dir) end unless branches.include?(branch_name) return false end true end |
#branch_exists_anywhere(branch_name, case_sensitive = false) ⇒ Object
Checks if branch exists ANYWHERE – Local, Remote, Code, DB. If the branch name is found anywhere, will return FALSE.
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/core/git.rb', line 713 def branch_exists_anywhere(branch_name, case_sensitive = false) # If new branch is 12345, find possible branches. if branch_name =~ /\A\d{4,5}\z/i branch_name = resolve_branch_for_jira(branch_name) end existing_branches = get_all_branches_as_array if case_sensitive existing_branches.map!(&:downcase) branch_name.downcase! end unless existing_branches.include?(branch_name) return false end true end |
#branch_has_upstream(repo_dir, branch_name) ⇒ Object
Checks if a branch has an upstream (remote) branch. Returns TRUE or FALSE.
732 733 734 735 736 737 |
# File 'lib/core/git.rb', line 732 def branch_has_upstream(repo_dir, branch_name) validate_repo_dir(repo_dir) update_origin(repo_dir) result = `cd #{repo_dir} && git branch -vv | grep 'origin/#{branch_name}'` result == '' ? false : true end |
#branch_is_up_to_date(repo_dir, branch_name) ⇒ Object
Checks if a branch is up-to-date with its remote
750 751 752 753 754 755 756 |
# File 'lib/core/git.rb', line 750 def branch_is_up_to_date(repo_dir, branch_name) validate_repo_dir(repo_dir) result_local = `cd #{repo_dir} && git rev-parse #{branch_name}` result_remote = `cd #{repo_dir} && git rev-parse origin/#{branch_name}` result_local == result_remote ? true : false end |
#branch_synced_with_upstream(repo_dir, branch_name) ⇒ Object
Checks if a branch is at same HEAD as upstream. Returns TRUE or FALSE.
742 743 744 745 746 |
# File 'lib/core/git.rb', line 742 def branch_synced_with_upstream(repo_dir, branch_name) validate_repo_dir(repo_dir) result = `cd #{repo_dir} && git branch -vv | grep 'origin/#{branch_name}'` result == '' ? false : true end |
#changes_exist(repo_dir) ⇒ Object
Returns TRUE if changes exist or FALSE if there is nothing to commit.
856 857 858 859 860 861 862 863 864 865 866 867 |
# File 'lib/core/git.rb', line 856 def changes_exist(repo_dir) validate_repo_dir(repo_dir) git_results = App::Terminal::command_capture('git status', repo_dir) changes_exist = true git_results = git_results[0].split("\n") git_results.each do |line| if line =~ /nothing to commit, working directory clean/ changes_exist = false end end changes_exist end |
#check_branch_does_not_exist_anywhere(branch_name) ⇒ Object
Checks that a branch DOESN’T exist anywhere (local, remote, code and db). If it does, will exit with error.
775 776 777 778 779 780 |
# File 'lib/core/git.rb', line 775 def check_branch_does_not_exist_anywhere(branch_name) App::Terminal::info("Checking if branch #{App::Terminal::format_branch(branch_name)} doesn't already exist somewhere...") if branch_exists_anywhere(branch_name) App::Terminal::error('Branch already exists', "Cannot continue because a branch named #{App::Terminal::format_branch(branch_name)}\x1B[38;5;240m already exists somewhere.", true) end end |
#check_branch_exists_somewhere(branch_name) ⇒ Object
Checks that a branch DOES exist somewhere (local, remote, code or db). If it does not, will exit with error.
784 785 786 787 788 |
# File 'lib/core/git.rb', line 784 def check_branch_exists_somewhere(branch_name) unless branch_exists_anywhere(branch_name) App::Terminal::error("Branch doesn't exist", "Cannot continue because branch #{App::Terminal::format_branch(branch_name)}\x1B[38;5;240m doesn't exist.", true) end end |
#check_for_conflicts(result, repo_dir, additional_info = nil) ⇒ Object
Pass the result of App::Terminal::command() and this should do the rest. Bombs out if you don’t confirm.
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 |
# File 'lib/core/git.rb', line 897 def check_for_conflicts(result, repo_dir, additional_info = nil) validate_repo_dir(repo_dir) error_array = [] unless additional_info.nil? error_array = [] if additional_info.is_a? Array additional_info.each do |info| error_array << info end else if additional_info.is_a? String error_array << additional_info else raise RuntimeError, "Expected String, got: #{additional_info.class}" end end end = "Merge conflict occurred in: #{get_repo_shorthand(repo_dir)}" error_array << "Please #{App::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing." conflict_resolved = (result == false) ? false : true changes_to_be_committed = false while conflict_resolved == false unless App::Terminal::prompt_yes_no(, error_array, "Have you #{App::Terminal::format_highlight('resolved', true)}\x1B[38;5;89m your conflicts?") App::Terminal::abort end conflict_resolved = true changes_to_be_committed = false = 'It seems there are still files which need resolving:' error_array = [] git_status = `git status` git_status.split("\n").each do |line| if line.strip =~ /\Aunmerged\spaths:\z/i conflict_resolved = false elsif line.strip =~ /\Aboth\smodified:/i conflict_resolved = false line_split = line.split('modified:') error_array << "\x1B[38;5;223m#{line_split[1].strip}\x1B[0m" elsif line.strip =~ /\Achanges\sto\sbe\scommitted:/i changes_to_be_committed = true end end end App::Terminal::command('git commit --no-edit', repo_dir) if changes_to_be_committed end |
#check_for_same_branch(display = SAME_BRANCH_WARNING) ⇒ Object
Checks if both repos are on same branch and displays either ERROR or WARNING.
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
# File 'lib/core/git.rb', line 610 def check_for_same_branch(display = SAME_BRANCH_WARNING) branch_code = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)) branch_db = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)) if branch_code != branch_db case display when SAME_BRANCH_WARNING App::Terminal::warning("You're code is on #{App::Terminal::format_highlight('2 different branches')}", [ "#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} is on #{App::Terminal::format_branch(branch_code)}", "#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))} is on #{App::Terminal::format_branch(branch_db)}" ]) when SAME_BRANCH_ERROR App::Terminal::error("You're code is on #{App::Terminal::format_highlight('2 different branches')}", [ "#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)))} is on #{App::Terminal::format_branch(branch_code)}", "#{App::Terminal::format_directory(get_repo_shorthand(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)))} is on #{App::Terminal::format_branch(branch_db)}", nil, 'You cannot run this command unless both of your repos are on the same branch.' ]) end return false end true end |
#check_for_stash(automatic = false) ⇒ Object
Checks if you currently have stashed changes for current branch and if so, prompt to un-stash them.
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/core/git.rb', line 564 def check_for_stash(automatic = false) repo_loop.each do |repo_dir| results = check_for_stash_get_stashes(repo_dir) if results.any? results_output = Array.new results.each do |result| results_output << "#{result}" end stashes_to_skip = 0 while results.any? stash_name = results[0].split(/:/).first if automatic || App::Terminal::prompt_yes_no("Found the following stash in #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))} on branch #{App::Terminal::format_branch(current_branch_for_repo(repo_dir))}", "#{results[0]}", "Would you like to #{App::Terminal::format_action('apply')}\x1B[38;5;89m this stash now?") App::Terminal::output('Un-stashing working changes', App::Terminal::MSG_AUTOMATIC) if automatic stash_apply_successful = App::Terminal::command(["git stash apply #{stash_name}"], repo_dir) if stash_apply_successful[0] == true App::Terminal::command("git stash drop #{stash_name}", repo_dir) results = check_for_stash_get_stashes(repo_dir) else App::Terminal::error("Stash could not be applied successfully (and therefore wasn't dropped).", ["#{results[0]}", nil, "Please #{App::Terminal::format_action('open an IDE')} and resolve your conflicts before continuing.", "Don't forget to drop your stash afterwards with: #{App::Terminal::format_command("git stash drop #{stash_name}")}"], false) results = [] end else stashes_to_skip = stashes_to_skip + 1 results = check_for_stash_get_stashes(repo_dir) a = (stashes_to_skip + 0) b = 0 while b < a do results.shift b += 1 end end end App::Terminal::command('git add .', repo_dir) end end end |
#check_for_stash_get_stashes(repo_dir) ⇒ Object
Sub-method for ‘show_branches’. Don’t call independently.
603 604 605 606 |
# File 'lib/core/git.rb', line 603 def check_for_stash_get_stashes(repo_dir) results = `cd #{repo_dir} && git stash list | grep 'WIP on #{current_branch_for_repo(repo_dir)}:'` results.split("\n") end |
#check_for_uncommitted_files(automatic = false, force_stash_message = false) ⇒ Object
Checks if you have staged changes in current repo and if so, prompts to stash them.
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/core/git.rb', line 539 def check_for_uncommitted_files(automatic = false, = false) repo_loop.each do |repo_dir| results = `cd #{repo_dir} && git status | grep 'Changes '` results = results.split("\n") if results.any? App::Terminal::command(['git status'], repo_dir) current_branch = current_branch_for_repo(repo_dir) if automatic || App::Terminal::prompt_yes_no("Found uncommitted files in #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))} on branch #{App::Terminal::format_branch(current_branch)}", nil, "Would you like to #{App::Terminal::format_action('stash')}\x1B[38;5;89m these changes before continuing?", false) App::Terminal::output('Stashing working changes', App::Terminal::MSG_AUTOMATIC) if automatic App::Terminal::command('git stash', repo_dir) else if != false = .is_a?(String) ? : nil App::Terminal::abort(, ["In this particular scenario, you #{App::Terminal::format_invalid('cannot continue', true)} unless you stash your changes."], true, false) end unless App::Terminal::prompt_yes_no('Continue without stashing?', "By selecting #{App::Terminal::format_action('Yes')}\x1B[38;5;240m, you're changes will be carried over to the next branch.", nil, false) App::Terminal::abort end end end end end |
#current_branch_for_repo(repo_dir) ⇒ Object
Get current branch for repo.
448 449 450 451 |
# File 'lib/core/git.rb', line 448 def current_branch_for_repo(repo_dir) validate_repo_dir(repo_dir) `cd #{repo_dir} && git symbolic-ref --short -q HEAD`.strip end |
#get_all_branches_as_array ⇒ Object
Gets EVERY SINGLE BRANCH that exists – local & remote, code & db – and puts them in a single, unique, array.
287 288 289 290 291 292 293 294 295 296 |
# File 'lib/core/git.rb', line 287 def get_all_branches_as_array unless @branches_as_array_all local_branches = get_branches_as_array(App::Git::LOCAL) remote_branches = get_branches_as_array(App::Git::REMOTE) @branches_as_array_all = local_branches[0].concat(local_branches[1]).concat(remote_branches[0]).concat(remote_branches[1]) @branches_as_array_all.uniq! @branches_as_array_all.sort_by! { |m| m.downcase } end @branches_as_array_all end |
#get_branches_as_array(local_remote = LOCAL, repo_dir = nil) ⇒ Object
Gets branch names as array.
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/core/git.rb', line 210 def get_branches_as_array(local_remote = LOCAL, repo_dir = nil) validate_local_remote(local_remote) # Check if result is already cached. if repo_dir.nil? if local_remote == LOCAL return @branches_as_array[:local_both] if @branches_as_array[:local_both] != nil else return @branches_as_array[:remote_both] if @branches_as_array[:remote_both] != nil end else if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) if local_remote == LOCAL return @branches_as_array[:local_code] if @branches_as_array[:local_code] != nil else return @branches_as_array[:remote_code] if @branches_as_array[:remote_code] != nil end else if local_remote == LOCAL return @branches_as_array[:local_db] if @branches_as_array[:local_db] != nil else return @branches_as_array[:remote_db] if @branches_as_array[:remote_db] != nil end end end case local_remote when LOCAL if repo_dir.nil? brightpearl_code, brightpearl_db = get_local_branches repos_branches = [brightpearl_code, brightpearl_db] else branches = get_local_branches(SORT_REFNAME, repo_dir) repos_branches = [branches] end else if repo_dir.nil? brightpearl_code, brightpearl_db = get_remote_branches repos_branches = [brightpearl_code, brightpearl_db] else branches = get_remote_branches(SORT_REFNAME, repo_dir) repos_branches = [branches] end end repos_to_return = [] repos_branches.each do |repo_data| branch_names = [] repo_data.each do |branch_data| branch_names << branch_data[:"#{REFNAME}"] end repos_to_return << branch_names end if repo_dir.nil? if local_remote == LOCAL return @branches_as_array[:local_both] = repos_to_return[0], repos_to_return[1] else return @branches_as_array[:remote_both] = repos_to_return[0], repos_to_return[1] end else if repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) if local_remote == LOCAL return @branches_as_array[:local_code] = repos_to_return[0] else return @branches_as_array[:remote_code] = repos_to_return[0] end else if local_remote == LOCAL return @branches_as_array[:local_db] = repos_to_return[0] else return @branches_as_array[:remote_db] = repos_to_return[0] end end end end |
#get_changed_files(repo_dir, branch_to_compare_to = "origin/#{App::Git::MASTER}") ⇒ Object
Get list of files that have changed between 2 branches
944 945 946 947 948 |
# File 'lib/core/git.rb', line 944 def get_changed_files(repo_dir, branch_to_compare_to = "origin/#{App::Git::MASTER}") validate_repo_dir(repo_dir) command = "git diff #{branch_to_compare_to}..#{current_branch_for_repo(repo_dir)} --name-only" App::Terminal::command_capture(command, repo_dir) end |
#get_local_branches(sort = SORT_REFNAME, repo_dir = nil) ⇒ Object
Gets detailed info about local branches as Array.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/core/git.rb', line 73 def get_local_branches(sort = SORT_REFNAME, repo_dir = nil) repos = [] repos_to_return = [] validate_sort(sort) if repo_dir.nil? repo_loop.each do |repo_dir_inner| repos << repo_dir_inner end else validate_repo_dir(repo_dir) repos << repo_dir end repos.each do |repo_dir_inner| unless File.directory?(File.(repo_dir_inner)) App::Terminal::error('Directory not found', "Directory doesn't exist: #{App::Terminal::format_directory(repo_dir_inner)}", true) end raw_terminal_output = ` cd #{repo_dir_inner} && git for-each-ref refs/heads/ --format='%(#{REFNAME})#{DELIMITER}%(#{OBJECT_TYPE})#{DELIMITER}%(#{OBJECT_SIZE})#{DELIMITER}%(#{OBJECT_NAME})#{DELIMITER}%(tree)#{DELIMITER}%(#{NUM_PARENT})#{DELIMITER}%(#{COMMITTER_NAME})#{DELIMITER}%(#{COMMITTER_EMAIL})#{DELIMITER}%(#{COMMITTER_DATE})#{DELIMITER}%(#{SUBJECT})#{DELIMITER}%(#{UPSTREAM})#{DELIMITER}' | sed 's/refs\\/heads\\///g' ` branches = {} branch_count = 0 raw_terminal_output.split("\n").each do |line| line_split = line.split(DELIMITER) data = {} data[:"#{REFNAME}"] = line_split[0] data[:"#{OBJECT_TYPE}"] = line_split[1] data[:"#{OBJECT_SIZE}"] = line_split[2] data[:"#{OBJECT_NAME}"] = line_split[3] data[:"#{TREE}"] = line_split[4] data[:"#{NUM_PARENT}"] = line_split[5] data[:"#{COMMITTER_NAME}"] = line_split[6] data[:"#{COMMITTER_EMAIL}"] = line_split[7][1..-2] data[:"#{COMMITTER_DATE}"] = DateTime.parse(line_split[8]) data[:"#{SUBJECT}"] = line_split[9] data[:"#{UPSTREAM}"] = line_split[10] case sort when SORT_REFNAME branches[data[:"#{REFNAME}"]] = data when SORT_DATE branches["#{data[:"#{COMMITTER_DATE}"].strftime('%Y-%m-%d-%H-%I-%S')}-#{branch_count}"] = data branch_count = branch_count + 1 else App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true) end end branch_keys = branches.keys case sort when SORT_REFNAME branch_keys.sort_by!(&:downcase) when SORT_DATE branch_keys.sort_by! { |value| value } branch_keys = branch_keys.reverse else App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true) end branch_data = [] branch_keys.each do |key| branch_data << branches["#{key}"] end repos_to_return << branch_data end if repo_dir.nil? return repos_to_return[0], repos_to_return[1] else repos_to_return[0] end end |
#get_remote_branches(sort = SORT_REFNAME, repo_dir = nil) ⇒ Object
Gets detailed info about remote branches as Array.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/core/git.rb', line 144 def get_remote_branches(sort = SORT_REFNAME, repo_dir = nil) repos = [] repos_to_return = [] validate_sort(sort) if repo_dir.nil? repo_loop.each do |repo_dir_inner| repos << repo_dir_inner end else validate_repo_dir(repo_dir) repos << repo_dir end repos.each do |repo_dir_inner| unless File.directory?(File.(repo_dir_inner)) App::Terminal::error('Directory not found', "Directory doesn't exist: #{App::Terminal::format_directory(repo_dir)}", true) end update_origin(repo_dir_inner) raw_terminal_output = ` cd #{repo_dir_inner} && for branch in \`git branch -r | grep -v HEAD\`; do echo \`git show --format="%cn#{DELIMITER}%ce#{DELIMITER}%cd#{DELIMITER}%s#{DELIMITER}" $branch | head -n 1\` $branch; done | sort -r | sed 's/origin\\///g' ` branches = {} branch_count = 0 raw_terminal_output.split("\n").each do |line| line_split = line.split(DELIMITER) data = {} data[:"#{COMMITTER_NAME}"] = line_split[0] data[:"#{COMMITTER_EMAIL}"] = line_split[1] data[:"#{COMMITTER_DATE}"] = DateTime.parse(line_split[2]) data[:"#{SUBJECT}"] = line_split[3] data[:"#{REFNAME}"] = line_split[4].to_s.strip case sort when SORT_REFNAME branches[data[:"#{REFNAME}"]] = data when SORT_DATE branches["#{data[:"#{COMMITTER_DATE}"].strftime('%Y-%m-%d-%H-%I-%S')}-#{branch_count}"] = data branch_count = branch_count + 1 else App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true) end end branch_keys = branches.keys case sort when SORT_REFNAME branch_keys.sort_by!(&:downcase) when SORT_DATE branch_keys.sort_by! { |value| value } branch_keys = branch_keys.reverse else App::Terminal::error('Sort not supported', "The following sorting option is not yet supported: #{sort}", true) end branch_data = [] branch_keys.each do |key| branch_data << branches["#{key}"] end repos_to_return << branch_data end if repo_dir.nil? return repos_to_return[0], repos_to_return[1] else repos_to_return[0] end end |
#get_repo_shorthand(repo_dir) ⇒ Object
Returns short-hand string for repo.
769 770 771 |
# File 'lib/core/git.rb', line 769 def get_repo_shorthand(repo_dir) repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) ? 'brightpearl-code' : 'brightpearl-db' end |
#merge_master_into_current_branch(repo_dir, push_to_origin = true) ⇒ Object
Merges master into current branch (for repo) and pushes changes to origin.
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/core/git.rb', line 495 def merge_master_into_current_branch(repo_dir, push_to_origin = true) current_branch = current_branch_for_repo(repo_dir) if current_branch == App::Git::MASTER return end commands = Array.new commands << 'git checkout master' commands << 'git pull' if current_branch != App::Git::MASTER commands << "git checkout #{current_branch}" commands << 'git pull' commands << 'git merge master' end if push_to_origin commands << 'git push' end App::Terminal::command(commands, repo_dir) end |
#repo_loop ⇒ Object
Returns array with the paths to both repos.
760 761 762 763 764 765 |
# File 'lib/core/git.rb', line 760 def repo_loop Array[ App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE), App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB) ] end |
#resolve_branch_for_jira(jira_number, ask_to_create = false) ⇒ Object
Resolves possible branch names from jira numbers (IE: BP-12345 from 12345)
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/core/git.rb', line 807 def resolve_branch_for_jira(jira_number, ask_to_create = false) resolved_branch = jira_number possible_branches = [] if jira_number =~ /\A\d{4,5}\z/ App::Terminal::automatic("Attempting to resolve branch for: #{App::Terminal::format_highlight(jira_number)}") get_all_branches_as_array.each do |possible_branch| if possible_branch =~ /#{jira_number}/i # If more than one possible branch exists, IE: bug-14145 & bp-14145 if possible_branches.any? App::Terminal::error("More than one possible branch found for jira number: #{App::Terminal::format_highlight(jira_number)}", [App::Terminal::format_branch(possible_branches[0]), App::Terminal::format_branch(possible_branch), nil, "In this case, you must specify the branch name #{App::Terminal::format_highlight('explicitly')}."], true) end possible_branches << possible_branch App::Terminal::output("Resolved branch #{App::Terminal::format_branch(possible_branch)} from jira number: #{App::Terminal::format_highlight(jira_number)}", App::Terminal::MSG_AUTOMATIC) end end unless possible_branches.any? if ask_to_create App::Terminal::error("No branch found for jira number: #{App::Terminal::format_highlight(jira_number)}", ['Please check your input and try again.'], true) # unless App::Terminal::prompt_yes_no("No branch found for jira number: #{App::Terminal::format_highlight(jira_number)}", nil, "Would you like to #{App::Terminal::format_action('CREATE')} branch ") # App::Terminal::abort # end # # # todo # # INSERT CODE TO CREATE NEW BRANCH HERE !! # App::Terminal::abort else App::Terminal::error("No branch found for jira number: #{App::Terminal::format_highlight(jira_number)}", ['Please check your input and try again.'], true) end end resolved_branch = possible_branches[0] end resolved_branch end |
#resolve_jira_for_branch(branch_name, exit_script = true) ⇒ Object
Resolves jira number from branch (IE: 12345 from BP-12345)
845 846 847 848 849 850 851 852 |
# File 'lib/core/git.rb', line 845 def resolve_jira_for_branch(branch_name, exit_script = true) if branch_name =~ /\d{4,5}/i match = branch_name.match(/\d{4,5}/i) match.to_s else branch_name end end |
#show_branches(sort = SORT_REFNAME, local_remote = LOCAL) ⇒ Object
Outputs list of branches to terminal.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/core/git.rb', line 300 def show_branches(sort = SORT_REFNAME, local_remote = LOCAL) # todo puts puts "\x1B[31mTODO!\x1B[0m Must do something with 'terminal_width' parameter." puts validate_sort(sort) validate_local_remote(local_remote) # terminal_width = HighLine::SystemExtensions.terminal_size # terminal_width = terminal_width[0] case local_remote when LOCAL brightpearl_code, brightpearl_db = get_local_branches(sort) else brightpearl_code, brightpearl_db = get_remote_branches(sort) end show_branches_draw_table(brightpearl_code, brightpearl_db) end |
#show_branches_divider(column_width, color = 'white') ⇒ Object
Sub-method for ‘show_branches’. Don’t call independently.
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/core/git.rb', line 430 def show_branches_divider(column_width, color = 'white') row do column(App::Terminal::fill(column_width[0], MDASH), :color => color) column(App::Terminal::fill(column_width[1], MDASH), :color => color) column(App::Terminal::fill(column_width[2], MDASH), :color => color) column(App::Terminal::fill(column_width[3], MDASH), :color => color) column(App::Terminal::fill(column_width[4], MDASH), :color => color) column(App::Terminal::fill(column_width[5], MDASH), :color => color) column(App::Terminal::fill(column_width[6], MDASH), :color => color) column(App::Terminal::fill(column_width[7], MDASH), :color => color) column(App::Terminal::fill(column_width[8], MDASH), :color => color) column(App::Terminal::fill(column_width[9], MDASH), :color => color) column(App::Terminal::fill(column_width[10], MDASH), :color => color) end end |
#show_branches_draw_table(brightpearl_code, brightpearl_db) ⇒ Object
Draws the actual table of branches.
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/core/git.rb', line 320 def show_branches_draw_table(brightpearl_code, brightpearl_db) current_code_branch = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)) current_db_branch = current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)) column_width = [2, 20, 23, 15, 34, 1, 34, 15, 23, 20, 1] App::Tools::validate_report_width(column_width) puts "\n" table(:border => false) do row do column('', :align => 'right', :bold => 'true', :width => column_width[0]) column('Last Activity', :align => 'right', :bold => 'true', :width => column_width[1]) column('Developer', :align => 'right', :bold => 'true', :width => column_width[2]) column('Last Commit', :align => 'right', :bold => 'true', :width => column_width[3]) column('BRIGHTPEARL-CODE', :align => 'right', :bold => 'true', :width => column_width[4], :color => 32) column('|', :align => 'center', :bold => 'true', :width => column_width[5]) column('BRIGHTPEARL-DB', :align => 'left', :bold => 'true', :width => column_width[6], :color => 160) column('Last Commit', :align => 'left', :bold => 'true', :width => column_width[7]) column('Developer', :align => 'left', :bold => 'true', :width => column_width[8]) column('Last Activity', :align => 'left', :bold => 'true', :width => column_width[9]) column('', :align => 'left', :bold => 'true', :width => column_width[10]) end show_branches_divider(column_width) db_branches_shown = [] brightpearl_code.each do |code_branch| db_branch = show_branches_get_db_branch(brightpearl_db, code_branch) if db_branch[:"#{REFNAME}"] != MDASH db_branches_shown << db_branch[:"#{REFNAME}"] end code_time_adjusted = code_branch[:"#{COMMITTER_DATE}"] - (1 / 24.0) row do code_accent, code_color, code_star, db_accent, db_color, db_star = show_branches_get_colors(code_branch, current_code_branch, current_db_branch, db_branch) column("#{code_star}", :color => code_color) column(App::Tools::time_passed_since(code_time_adjusted), :color => code_color) column(code_branch[:"#{COMMITTER_NAME}"], :color => code_color) column(code_branch[:"#{COMMITTER_DATE}"].strftime('%d %^b %H:%M'), :color => code_color) column(code_branch[:"#{REFNAME}"], :color => code_accent) column('|') column(db_branch[:"#{REFNAME}"], :color => db_accent) column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : db_branch[:"#{COMMITTER_DATE}"].strftime('%d %^b %H:%M'), :color => db_color) column(db_branch[:"#{COMMITTER_NAME}"], :color => db_color) column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : App::Tools::time_passed_since(db_branch[:"#{COMMITTER_DATE}"] - (1 / 24.0)), :color => db_color) column("#{db_star}", :color => db_color) end end brightpearl_db.each do |db_branch| unless db_branches_shown.include? db_branch[:"#{REFNAME}"] row do code_accent, code_color, code_star, db_accent, db_color, db_star = show_branches_get_colors(nil, current_code_branch, current_db_branch, db_branch) column('', :color => code_color) column(MDASH, :color => code_color) column(MDASH, :color => code_color) column(MDASH, :color => code_color) column(MDASH, :color => code_accent) column('|') column(db_branch[:"#{REFNAME}"], :color => db_accent) column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : db_branch[:"#{COMMITTER_DATE}"].strftime('%d %^b %H:%M'), :color => db_color) column(db_branch[:"#{COMMITTER_NAME}"], :color => db_color) column((db_branch[:"#{COMMITTER_DATE}"] == nil) ? MDASH : App::Tools::time_passed_since(db_branch[:"#{COMMITTER_DATE}"]), :color => db_color) column('') end end end show_branches_divider(column_width) end puts "\n" end |
#show_branches_get_colors(code_branch, current_code_branch, current_db_branch, db_branch) ⇒ Object
Sub-method for ‘show_branches’. Don’t call independently.
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/core/git.rb', line 388 def show_branches_get_colors(code_branch, current_code_branch, current_db_branch, db_branch) code_star = nil code_color = 240 code_accent = nil db_star = nil db_color = 240 db_accent = nil current_branch_color = 46 unless code_branch.nil? if current_code_branch == code_branch[:"#{REFNAME}"] code_star = "\xe2\x98\x85" code_color = current_branch_color code_accent = current_branch_color end end unless db_branch.nil? if current_db_branch == db_branch[:"#{REFNAME}"] db_star = "\xe2\x98\x85" db_color = current_branch_color db_accent = current_branch_color end end return code_accent, code_color, code_star, db_accent, db_color, db_star end |
#show_branches_get_db_branch(brightpearl_db, code_branch) ⇒ Object
Sub-method for ‘show_branches’. Don’t call independently.
415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/core/git.rb', line 415 def show_branches_get_db_branch(brightpearl_db, code_branch) brightpearl_db.each do |db_branch| if db_branch[:"#{REFNAME}"] == code_branch[:"#{REFNAME}"] return db_branch end end db_branch = {} db_branch[:"#{REFNAME}"] = MDASH db_branch[:"#{COMMITTER_NAME}"] = MDASH db_branch[:"#{COMMITTER_DATE}"] = nil db_branch end |
#update_origin(repo_dir = nil) ⇒ Object
Updates origin (IE: remote branches)
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/core/git.rb', line 455 def update_origin(repo_dir = nil) validate_repo_dir(repo_dir) epoch_current = Time.now.strftime('%s') unless App::UtilsFiles::file_exists(GIT_LAST_GIT_FETCH_FILE) App::UtilsFiles::write_file(GIT_LAST_GIT_FETCH_FILE, [epoch_current]) end unless @origin_updated_code && repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) || @origin_updated_db && repo_dir == App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB) || @origin_updated_code && @origin_updated_db && repo_dir.nil? # IF ORIGIN WAS UPDATED IN THE LAST HOUR, DON'T DO IT AGAIN epoch_last_fetch = App::UtilsFiles::read_file(GIT_LAST_GIT_FETCH_FILE)[0] time_difference = epoch_current.to_i - epoch_last_fetch.to_i if time_difference < 3600 App::UtilsFiles::write_file(GIT_LAST_GIT_FETCH_FILE, [epoch_current]) App::Terminal::output("Origin already up to date \xe2\x80\x94 #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}") return end App::Terminal::output("Updating origin \xe2\x80\x94 #{App::Terminal::format_directory(get_repo_shorthand(repo_dir))}") case repo_dir when App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE) @origin_updated_code = true App::Terminal::command(['git fetch -p'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)) when App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB) @origin_updated_db = true App::Terminal::command(['git fetch -p'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB)) else @origin_updated_code = true @origin_updated_db = true repo_loop.each do |repo_dir_inner| App::Terminal::command(['git fetch -p'], repo_dir_inner) end end end end |
#validate_code_db(code_db) ⇒ Object
Validates that a parameter is either ‘code’ or ‘db’
961 962 963 964 965 |
# File 'lib/core/git.rb', line 961 def validate_code_db(code_db) unless Array[CODE, DB].include?(code_db) abort("'#{code_db}' is not a valid parameter. Must be CODE or DB.") end end |
#validate_local_remote(local_remote) ⇒ Object
Validates that a parameter is either ‘local’ or ‘remote’
953 954 955 956 957 |
# File 'lib/core/git.rb', line 953 def validate_local_remote(local_remote) unless Array[LOCAL, REMOTE].include?(local_remote) ("'#{local_remote}' is not a valid parameter. Must be LOCAL or REMOTE.") end end |
#validate_repo_dir(repo_dir) ⇒ Object
Makes sure the repo directory is valid.
969 970 971 972 973 974 975 976 |
# File 'lib/core/git.rb', line 969 def validate_repo_dir(repo_dir) unless Array[ App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE), App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_DB) ].include?(repo_dir) abort("'#{repo_dir}' is not a valid directory.") end end |
#validate_sort(sort_option) ⇒ Object
Validates if sort option is supported.
980 981 982 983 984 |
# File 'lib/core/git.rb', line 980 def validate_sort(sort_option) unless Array[SORT_DATE, SORT_REFNAME].include?(sort_option) abort("'#{sort_option}' is not a valid sort option.") end end |
#verify_same_branch ⇒ Object
Makes sure that both BP-CODE & BP-DB are on the same branch.
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/core/git.rb', line 517 def verify_same_branch branch_names = Array.new repo_loop.each do |repo_dir| branch_names << current_branch_for_repo(repo_dir) end if branch_names[0] != branch_names[1] puts puts "\x1B[41m ERROR \x1B[0m Cannot continue because your repos are not on the same branch." puts puts "\x1B[33m/brightpearl-code\x1B[0m is on: \x1B[32m#{branch_names[0]}\x1B[0m" puts "\x1B[33m/brightpearl-db \x1B[0m is on: \x1B[32m#{branch_names[1]}\x1B[0m" puts puts "Use \x1B[33mbrightpearl checkout\x1B[0m \x1B[32m[branch-name]\x1B[0m to switch both repos to the same branch." puts exit end branch_names[0] end |