Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Commit 42292f5

Browse files
committed
## Version 1.0.14
- Improved argument handling - Improved array iteration - Improved init and handling new empty repo
1 parent 4e74aa7 commit 42292f5

17 files changed

+1090
-441
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
## Version 1.0.14
2+
- Improved argument handling
3+
- Improved array iteration
4+
- Improved init and handling new empty repo
5+
16
## Version 1.0.13
27
- Added conflicts listing
3-
- added kubectl ordered resources listing
8+
- Added kubectl ordered resources listing
49

510
## Version 1.0.12
611
- Added init --default-branch parameter for setting default branch for the repo

smud-cli/.bash_aliases

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
alias smud='bash ~/smud-cli/smud.sh'
2+
alias git-resolve-conflict='bash ~/smud-cli/git-tools/git-resolve-conflict'
23
alias eche='echo -e'

smud-cli/download-and-install-cli.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
old_SEP=$IFS
23
HOME_DIR="$(dirname `readlink -f ~/.bashrc`)"
34
VERSION="LATEST"
45
folder=smud-cli
@@ -109,4 +110,6 @@ if [ -d $download_folder ]; then
109110

110111
rm -rf $download_folder
111112
. $destination_folder/install-cli.sh
112-
fi
113+
fi
114+
115+
IFS=$old_SEP

smud-cli/functions-conflicts.sh

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,99 @@ print_verbose "**** START: functions-conflicts.sh"
33
conflicts()
44
{
55
if [ "$help" ]; then
6-
echo "${bold}smud conflict(s)${normal}: Scan and list conflicts in yaml-files."
7-
return
6+
echo "${bold}smud conflict(s)${normal} [options]: List conflicts in yaml-files or resolve conflicts in conflictiong files."
7+
echo ""
8+
echo "Options:"
9+
echo " <no-options>: Scan and list conflicts in yaml-files."
10+
echo " --merge-ours=, --ours:"
11+
echo " Merge conflicts with our versions"
12+
echo " --merge-theirs=, --theirs:"
13+
echo " Merge conflicts with their versions"
14+
echo " --merge-union=, --union:"
15+
echo " Merge conflicts with union versions"
16+
17+
fi
18+
19+
exit_if_is_not_a_git_repository
20+
21+
if [ "$merge_ours" ]; then
22+
if [ ! "$conflicts_files" ]; then
23+
conflicts_files=$(git-list-conflict 'files')
24+
fi
25+
printf "${white}Resolve conflicts based on ours version.\n"
26+
for file in $conflicts_files;do
27+
git-resolve-conflict "--ours" "$file"
28+
done
29+
elif [ "$merge_theirs" ]; then
30+
if [ ! "$conflicts_files" ]; then
31+
conflicts_files=$(git-list-conflict 'files')
32+
fi
33+
printf "${white}Resolve conflicts based on their version.\n"
34+
for file in $conflicts_files;do
35+
git-resolve-conflict "--theirs" "$file"
36+
done
37+
elif [ "$merge_union" ]; then
38+
if [ ! "$conflicts_files" ]; then
39+
conflicts_files=$(git-list-conflict 'files')
40+
fi
41+
printf "${white}Resolve conflicts based on union version.\n"
42+
for file in $conflicts_files;do
43+
git-resolve-conflict "--union" "$file"
44+
done
45+
else
46+
git-list-conflict
847
fi
9-
if [ ! "$is_repo" ]; then
10-
printf "${red}'$(pwd)' is not a git repository! ${normal}\n"
48+
49+
}
50+
git-list-conflict() {
51+
if [ "$1" == "files" ]; then
52+
sh -c "find $find_files_filter -name '*.yaml' -exec grep -H -e '>>>' -e '<<<' {} \;" | awk --field-separator=: '{ print $1}'|uniq
1153
return
1254
fi
55+
1356
printf "${white}Scan and list conflicts in yaml-files.\n"
1457

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

61+
git-resolve-conflict() {
62+
STRATEGY="$1"
63+
FILE_PATH="$2"
64+
if [ -z "$FILE_PATH" ] || [ -z "$STRATEGY" ]; then
65+
echo "Usage: smud conflicts <strategy> <file>"
66+
echo ""
67+
echo "Example: git-resolve-conflict --ours package.json"
68+
echo "Example: git-resolve-conflict --union package.json"
69+
echo "Example: git-resolve-conflict --theirs package.json"
70+
return
71+
fi
72+
73+
if [ ! -f "$FILE_PATH" ]; then
74+
echo "$FILE_PATH does not exist; aborting."
75+
return
76+
fi
77+
78+
# remove leading ./ if present, to match the output of git diff --name-only
79+
# (otherwise if user input is './filename.txt' we would not match 'filename.txt')
80+
FILE_PATH_FOR_GREP=${FILE_PATH#./}
81+
# grep -Fxq: match string (F), exact (x), quiet (exit with code 0/1) (q)
82+
if ! git diff --name-only --diff-filter=U | grep -Fxq "$FILE_PATH_FOR_GREP"; then
83+
echo "$FILE_PATH is not in conflicted state; aborting."
84+
return
85+
fi
86+
87+
git show :1:"$FILE_PATH" > ./tmp.common
88+
git show :2:"$FILE_PATH" > ./tmp.ours
89+
git show :3:"$FILE_PATH" > ./tmp.theirs
90+
91+
git merge-file "$STRATEGY" -p ./tmp.ours ./tmp.common ./tmp.theirs > "$FILE_PATH"
92+
git add "$FILE_PATH"
93+
94+
rm ./tmp.common
95+
rm ./tmp.ours
96+
rm ./tmp.theirs
97+
}
98+
99+
100+
18101
print_verbose "**** END: functions-conflicts.sh"

smud-cli/functions-gitops.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ gitops_model__show_changelog_file()
9494
if [ "$changelog_content" ]; then
9595
print "$context GitOps-model Changelog:"
9696
echo -e "$blue$changelog_content$reset"
97-
IFS=$'\n';read -rd '' -a changelog_commits <<< "$changelog_commits"
98-
97+
old_SEP=$IFS
98+
IFS=$'\n'
9999
for commit in "${changelog_commits[@]}"
100100
do
101101
git show $commit:CHANGELOG.md --pretty=format:%Cblue
102102
done
103+
IFS=$old_SEP
103104
else
104105
print "No $context GitOps-model Changelog found!"
105106
fi

0 commit comments

Comments
 (0)