-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git_utils/config.dev.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
## GIT Helpers for ManageIQ | ||
|
||
Following scripts iterate over core and plugins and performs useful mass operations. | ||
|
||
### Config | ||
|
||
[config.sh](config.sh) file contains basic settings, like your home and plugins directory of ManageIQ. | ||
If you want to redefine some value, create `config.dev.sh` file (excluded from git) and override variable. | ||
|
||
### Repositories | ||
|
||
List of repositories are either generated automatically (`$custom_repo_list == 0`) or you can define your own array manually | ||
(`$custom_repo_list == 1`). See config for example. | ||
|
||
### Scripts | ||
|
||
- [pull.sh](pull.sh): Checkouts all unchanged repos to master and pulls changes | ||
- [rebase.sh](rebase.sh): For all unchanged repos does the same as pull.sh and then rebases your current branch | ||
- [list-branches.sh](list-branches.sh): Prints current branches in all repos | ||
- [list-changes.sh](list-changes.sh): Prints changes in all repos | ||
- [cleanup.sh](scripts/git/cleanup.sh): Deletes branches merged to master | ||
- Without args: local branches only | ||
- With `--remote-cleanup` arg: also deletes merged remote branches | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# Script for git cleanup - delete merged branches | ||
# Switches to master branches | ||
# | ||
# Usage: cleanup.sh [--remote-cleanup] | ||
|
||
source config.sh | ||
|
||
case $1 in | ||
-f|--remote-cleanup) remote_cleanup=1;; | ||
esac | ||
|
||
cd ${manageiq_root} | ||
|
||
for path in ${repositories[@]} | ||
do | ||
repo=$(basename ${path}) | ||
echo "${repo} -------------------------------------------------------" | ||
cd ${path} | ||
|
||
# This has to be run from master | ||
git checkout master | ||
|
||
# Update our list of remotes | ||
git fetch | ||
git remote prune origin | ||
|
||
# Remove local fully merged branches | ||
local_merged=$(git branch --merged master | grep -v 'master$') | ||
if [[ -z ${local_merged} ]]; then | ||
echo "No local branches to delete" | ||
else | ||
echo ${local_merged} | xargs git branch -d | ||
fi | ||
|
||
|
||
has_upstream=`git branch -a | grep upstream | wc -l` | ||
|
||
if [[ ${remote_cleanup} -eq 1 && "$has_upstream" -gt "0" ]] | ||
then | ||
remote_merged=$(git branch -r --merged master | sed 's/ *origin\///' | grep -v 'master$') | ||
if [[ -z ${remote_merged} ]]; then | ||
echo "No remote branches to delete" | ||
else | ||
# Remove remote fully merged branches | ||
echo ${remote_merged} | xargs -I% git push origin :% | ||
fi | ||
fi | ||
cd .. | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
# You can override these values in file config.dev.sh | ||
homedir=~ | ||
eval homedir=${homedir} | ||
manageiq_root="${homedir}/Projects/ManageIQ/upstream" | ||
plugins_dir="plugins" | ||
|
||
if [[ -f "./config.dev.sh" ]]; then | ||
source "config.dev.sh" | ||
fi | ||
|
||
# $custom_repo_list: | ||
# - when 0, then all repos in $manageiq_root and plugins are used | ||
# - when 1, user-defined list ${repositories} is used. | ||
# Can be defined in config.dev.sh (see example below) | ||
custom_repo_list=0 | ||
#repositories=("${manageiq_root}" | ||
# "${manageiq_root}/${plugins_dir}/manageiq-ui-classic" | ||
# "${manageiq_root}/${plugins_dir}/manageiq-api") | ||
|
||
source repositories.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
# List of current branches in MiQ repositories | ||
|
||
source config.sh | ||
|
||
cd ${manageiq_root} | ||
|
||
for path in ${repositories[@]} | ||
do | ||
cd ${path} | ||
current_branches=$(git branch) | ||
echo "" | ||
echo $(basename ${path}) | ||
echo "${current_branches}" | ||
cd .. | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Script for list your changes in all repos | ||
# | ||
# NOTE: Edit your variables below! | ||
source config.sh | ||
|
||
cd ${manageiq_root} | ||
|
||
empty_line=1 | ||
|
||
for path in ${repositories[@]} | ||
do | ||
cd ${path} | ||
repo=$(basename ${path}) | ||
current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
if git diff-index --quiet HEAD --; then | ||
echo "${repo}: No Changes (${current_branch})" | ||
empty_line=0 | ||
else | ||
if [[ ${empty_line} -eq 0 ]]; then | ||
echo "" | ||
fi | ||
echo "<$repo> -------------------------------------------------------" | ||
git status -s -b | ||
echo "</$repo> ------------------------------------------------------" | ||
echo "" | ||
empty_line=1 | ||
fi | ||
|
||
cd .. | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
# Script for git updating git branch master topology inventory plugins | ||
# Switches to master branches | ||
source config.sh | ||
|
||
cd ${manageiq_root} | ||
|
||
modified_repos=() | ||
|
||
for path in ${repositories[@]} | ||
do | ||
repo=$(basename ${path}) | ||
|
||
echo "${repo} -------------------------------------------------------" | ||
cd ${path} | ||
current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
|
||
if git diff-index --quiet HEAD --; then | ||
git fetch --all --prune | ||
git checkout master | ||
|
||
has_upstream=`git branch -a | grep upstream | wc -l` | ||
|
||
if [[ "$has_upstream" -gt "0" ]]; then | ||
git pull upstream master | ||
else | ||
git pull origin master | ||
fi | ||
else | ||
echo "Changes in branch ${current_branch}" | ||
modified_repos+=(${repo}) | ||
fi | ||
|
||
cd .. | ||
done | ||
|
||
echo "" | ||
echo "Repositories with changes (cannot apply git pull):" | ||
for repo in ${modified_repos[@]} | ||
do | ||
echo ${repo} | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
|
||
# Script for git updating master git branch an rebase current working branch | ||
|
||
source config.sh | ||
|
||
cd ${manageiq_root} | ||
|
||
modified_repos=() | ||
|
||
for path in ${repositories[@]} | ||
do | ||
echo "${repo} -------------------------------------------------------" | ||
cd ${path} | ||
current_branch=$(git rev-parse --abbrev-ref HEAD) | ||
|
||
|
||
if git diff-index --quiet HEAD --; then | ||
echo "* Updating (rebase) branch ${current_branch}" | ||
git fetch --all --prune | ||
git checkout master | ||
|
||
has_upstream=`git branch -a | grep upstream | wc -l` | ||
|
||
if [[ "$has_upstream" -gt "0" ]]; then | ||
git pull upstream master | ||
else | ||
git pull origin master | ||
fi | ||
|
||
if [[ ${current_branch} -ne "master" ]]; then | ||
git checkout ${current_branch} | ||
git rebase master | ||
fi | ||
else | ||
echo "Cannot update branch ${current_branch}: Modified files present" | ||
modified_repos+=(${repo}) | ||
fi | ||
|
||
cd .. | ||
done | ||
|
||
echo "" | ||
echo "Repositories with changes (cannot apply git rebase):" | ||
for repo in ${modified_repos[@]} | ||
do | ||
echo ${repo} | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ ${custom_repo_list} -eq 0 ]]; then | ||
repositories=("${manageiq_root}") | ||
idx=1 | ||
for dir in ${manageiq_root}/${plugins_dir}/* | ||
do | ||
if [[ -d ${dir} ]]; then | ||
repositories[${idx}]=${dir} | ||
idx=$((idx+1)) | ||
fi | ||
done | ||
fi |