Skip to content

Commit

Permalink
shell-check
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush committed Feb 11, 2024
1 parent 2595549 commit 3252162
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions scripts/format_as_fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ set -x
script_dir=$(dirname "$0")

commit_msg_remove_header="format: remove avalanche header"
commit_msg_remove_upstream="format: remove upstream go-ethereum"
commit_msg_rename_packages_as_fork="format: rename packages as fork"

make_commit() {
if git diff-index --cached --quiet HEAD --; then
Expand All @@ -19,15 +21,15 @@ make_commit() {

revert_by_message() {
hash=$(git log --grep="$1" --format="%H" -n 1)
git revert --no-edit $hash
git revert --no-edit "$hash"
}

if git status --porcelain | grep -q '^ M'; then
echo "There are edited files in the repository. Please commit or stash them before running this script."
exit 1
fi

upstream_dirs=$(cat "${script_dir}"/geth-allowed-packages.txt | sed -e 's/"github.com\/ethereum\/go-ethereum\/\(.*\)"/\1/' | xargs)
upstream_dirs=$(sed -e 's/"github.com\/ethereum\/go-ethereum\/\(.*\)"/\1/' "${script_dir}"/geth-allowed-packages.txt | xargs)
for dir in ${upstream_dirs}; do
if [ -d "${dir}" ]; then
git rm -r "${dir}"
Expand All @@ -48,4 +50,4 @@ go mod tidy
git add -u .
make_commit "${commit_msg_rename_packages_as_fork}"

revert_by_message "${commit_msg_remove_upstream}"
revert_by_message "${commit_msg_remove_header}"
11 changes: 7 additions & 4 deletions scripts/format_as_upstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ git add -u .
make_commit "${commit_msg_remove_header}"

upstream_tag=$(grep -o 'github.com/ethereum/go-ethereum v.*' go.mod | cut -f2 -d' ')
upstream_dirs=$(cat "${script_dir}"/geth-allowed-packages.txt | sed -e 's/"github.com\/ethereum\/go-ethereum\/\(.*\)"/\1/' | xargs)
git clean -f ${upstream_dirs}
git checkout "${upstream_tag}" -- ${upstream_dirs}
git add ${upstream_dirs}
upstream_dirs=$(sed -e 's/"github.com\/ethereum\/go-ethereum\/\(.*\)"/\1/' "${script_dir}"/geth-allowed-packages.txt | xargs)
upstream_dirs_array=()
IFS=" " read -r -a upstream_dirs_array <<< "$upstream_dirs"

git clean -f "${upstream_dirs_array[@]}"
git checkout "${upstream_tag}" -- "${upstream_dirs_array[@]}"
git add "${upstream_dirs_array[@]}"
make_commit "${commit_msg_add_upstream}"

sed_command='s!\([^/]\)github.com/ava-labs/subnet-evm!\1github.com/ethereum/go-ethereum!g'
Expand Down

0 comments on commit 3252162

Please sign in to comment.