Skip to content

Commit

Permalink
## Version 1.0.14
Browse files Browse the repository at this point in the history
- Improved argument handling
- Improved array iteration
- Improved init and handling new empty repo
  • Loading branch information
aho-dips committed Jun 13, 2024
1 parent 4e74aa7 commit 42292f5
Show file tree
Hide file tree
Showing 17 changed files with 1,090 additions and 441 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## Version 1.0.14
- Improved argument handling
- Improved array iteration
- Improved init and handling new empty repo

## Version 1.0.13
- Added conflicts listing
- added kubectl ordered resources listing
- Added kubectl ordered resources listing

## Version 1.0.12
- Added init --default-branch parameter for setting default branch for the repo
Expand Down
1 change: 1 addition & 0 deletions smud-cli/.bash_aliases
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
alias smud='bash ~/smud-cli/smud.sh'
alias git-resolve-conflict='bash ~/smud-cli/git-tools/git-resolve-conflict'
alias eche='echo -e'
5 changes: 4 additions & 1 deletion smud-cli/download-and-install-cli.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
old_SEP=$IFS
HOME_DIR="$(dirname `readlink -f ~/.bashrc`)"
VERSION="LATEST"
folder=smud-cli
Expand Down Expand Up @@ -109,4 +110,6 @@ if [ -d $download_folder ]; then

rm -rf $download_folder
. $destination_folder/install-cli.sh
fi
fi

IFS=$old_SEP
91 changes: 87 additions & 4 deletions smud-cli/functions-conflicts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,99 @@ print_verbose "**** START: functions-conflicts.sh"
conflicts()
{
if [ "$help" ]; then
echo "${bold}smud conflict(s)${normal}: Scan and list conflicts in yaml-files."
return
echo "${bold}smud conflict(s)${normal} [options]: List conflicts in yaml-files or resolve conflicts in conflictiong files."
echo ""
echo "Options:"
echo " <no-options>: Scan and list conflicts in yaml-files."
echo " --merge-ours=, --ours:"
echo " Merge conflicts with our versions"
echo " --merge-theirs=, --theirs:"
echo " Merge conflicts with their versions"
echo " --merge-union=, --union:"
echo " Merge conflicts with union versions"

fi

exit_if_is_not_a_git_repository

if [ "$merge_ours" ]; then
if [ ! "$conflicts_files" ]; then
conflicts_files=$(git-list-conflict 'files')
fi
printf "${white}Resolve conflicts based on ours version.\n"
for file in $conflicts_files;do
git-resolve-conflict "--ours" "$file"
done
elif [ "$merge_theirs" ]; then
if [ ! "$conflicts_files" ]; then
conflicts_files=$(git-list-conflict 'files')
fi
printf "${white}Resolve conflicts based on their version.\n"
for file in $conflicts_files;do
git-resolve-conflict "--theirs" "$file"
done
elif [ "$merge_union" ]; then
if [ ! "$conflicts_files" ]; then
conflicts_files=$(git-list-conflict 'files')
fi
printf "${white}Resolve conflicts based on union version.\n"
for file in $conflicts_files;do
git-resolve-conflict "--union" "$file"
done
else
git-list-conflict
fi
if [ ! "$is_repo" ]; then
printf "${red}'$(pwd)' is not a git repository! ${normal}\n"

}
git-list-conflict() {
if [ "$1" == "files" ]; then
sh -c "find $find_files_filter -name '*.yaml' -exec grep -H -e '>>>' -e '<<<' {} \;" | awk --field-separator=: '{ print $1}'|uniq
return
fi

printf "${white}Scan and list conflicts in yaml-files.\n"

sh -c "find $find_files_filter -name '*.yaml' -exec grep -H -e '>>>' -e '<<<' {} \;"
}

git-resolve-conflict() {
STRATEGY="$1"
FILE_PATH="$2"
if [ -z "$FILE_PATH" ] || [ -z "$STRATEGY" ]; then
echo "Usage: smud conflicts <strategy> <file>"
echo ""
echo "Example: git-resolve-conflict --ours package.json"
echo "Example: git-resolve-conflict --union package.json"
echo "Example: git-resolve-conflict --theirs package.json"
return
fi

if [ ! -f "$FILE_PATH" ]; then
echo "$FILE_PATH does not exist; aborting."
return
fi

# remove leading ./ if present, to match the output of git diff --name-only
# (otherwise if user input is './filename.txt' we would not match 'filename.txt')
FILE_PATH_FOR_GREP=${FILE_PATH#./}
# grep -Fxq: match string (F), exact (x), quiet (exit with code 0/1) (q)
if ! git diff --name-only --diff-filter=U | grep -Fxq "$FILE_PATH_FOR_GREP"; then
echo "$FILE_PATH is not in conflicted state; aborting."
return
fi

git show :1:"$FILE_PATH" > ./tmp.common
git show :2:"$FILE_PATH" > ./tmp.ours
git show :3:"$FILE_PATH" > ./tmp.theirs

git merge-file "$STRATEGY" -p ./tmp.ours ./tmp.common ./tmp.theirs > "$FILE_PATH"
git add "$FILE_PATH"

rm ./tmp.common
rm ./tmp.ours
rm ./tmp.theirs
}



print_verbose "**** END: functions-conflicts.sh"
5 changes: 3 additions & 2 deletions smud-cli/functions-gitops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ gitops_model__show_changelog_file()
if [ "$changelog_content" ]; then
print "$context GitOps-model Changelog:"
echo -e "$blue$changelog_content$reset"
IFS=$'\n';read -rd '' -a changelog_commits <<< "$changelog_commits"

old_SEP=$IFS
IFS=$'\n'
for commit in "${changelog_commits[@]}"
do
git show $commit:CHANGELOG.md --pretty=format:%Cblue
done
IFS=$old_SEP
else
print "No $context GitOps-model Changelog found!"
fi
Expand Down
Loading

0 comments on commit 42292f5

Please sign in to comment.