Skip to content

Commit

Permalink
fix: fix husky scripts not being POSIX compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
alanrodas committed Apr 16, 2024
1 parent 57b72bc commit 690f2ab
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env sh

# Load husky
. "$(dirname -- "$0")/_/husky.sh"
. "$(dirname -- "$0")/_/husky.sh";

# Read parameters
COMMIT_MSG_FILE=$1;

# Set failing on command fail, pipe fail, and undefined variable use
set -euo pipefail
set -eu;

# This hook is invoked by git-commit and git-merge, and can be
# bypassed with the --no-verify option. It takes a single
Expand Down
17 changes: 17 additions & 0 deletions .husky/hooks/pre-commit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* *****************************************************************************
* Copyright (C) National University of Quilmes 2018-2024
* Gobstones (TM) is a trademark of the National University of Quilmes.
*
* This program is free software distributed under the terms of the
* GNU Affero General Public License version 3.
* Additional terms added in compliance to section 7 of such license apply.
*
* You may read the full license at https://gobstones.github.io/gobstones-guidelines/LICENSE.
* *****************************************************************************
*/
import { run, npx } from '../_/utilities';

export default () => {

}
43 changes: 43 additions & 0 deletions .husky/hooks/prepare-commit-msg.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* *****************************************************************************
* Copyright (C) National University of Quilmes 2018-2024
* Gobstones (TM) is a trademark of the National University of Quilmes.
*
* This program is free software distributed under the terms of the
* GNU Affero General Public License version 3.
* Additional terms added in compliance to section 7 of such license apply.
*
* You may read the full license at https://gobstones.github.io/gobstones-guidelines/LICENSE.
* *****************************************************************************
*/
import { run, npx } from '../_/utilities';

type CommitMessageSource = 'commit' | 'squash' | 'merge' | 'template' | 'message';

export default (commitMessageFile: string, commitSource?: CommitMessageSource, sha1?: string) => {
console.log('Function called successfully');
if (
isAmend(commitSource, sha1) ||
commitSource === 'squash' ||
commitSource === 'merge'
) {
return 0;
}
if (commitSource === 'message') {
console.log('Setting a message through -m or -F option in this project ' +
'has been disabled. Please run a simple commit.\n'
);
return 1;
}
if (commitSource === 'template') {
console.log('Setting a template through -t or commit.template in this project ' +
'has been disabled. Please run a simple commit.\n'
);
return 1;
}
return npx('cz', '--hook');
}

function isAmend(commitSource?: CommitMessageSource, sha1?: string) {
return commitSource === 'commit' && sha1;
}
Binary file added .husky/husky.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env sh

# Load husky
. "$(dirname -- "$0")/_/husky.sh"
. "$(dirname -- "$0")/_/husky.sh";

# Read parameters
# NOTHING TO READ HERE

# Set failing on command fail, pipe fail, and undefined variable use
set -euo pipefail
set -eu;

# This hook is invoked by git-commit, and can be bypassed with the
# --no-verify option. It takes no parameters, and is invoked before
Expand Down
44 changes: 23 additions & 21 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,32 @@ REMOTE_NAME=$1;
REMOTE_URL=$2;
# Read the input and split it approprietly
INPUT=$(cat);
INPUT_ARR[0]='';
INPUT_ARR[1]='';
INPUT_ARR[2]='';
INPUT_ARR[3]='';
read -a INPUT_ARR <<< "$INPUT";
I=0
for WORD in $INPUT; do
case $I in
0)
LOCAL_REF=$WORD;;
1)
LOCAL_OBJ_NAME=$WORD;;
2)
REMOTE_REF=$WORD;;
3)
REMOTE_OBJ_NAME=$WORD;;
esac
I=$(I + 1)
done

LOCAL_REF=${INPUT_ARR[0]}
LOCAL_OBJ_NAME=${INPUT_ARR[1]}
REMOTE_REF=${INPUT_ARR[2]}
REMOTE_OBJ_NAME=${INPUT_ARR[3]}
case "$LOCAL_REF" in
refs\/tags*)
# Apply specific code when publishing tags
IS_TAG=1;;
*)
# Apply specific code when publishing any branch
IS_TAG=0;;
esac

# Set failing on command fail, pipe fail, and undefined variable use
set -euo pipefail
set -eu;

# This hook is called by git-push and can be used to prevent a
# push from taking place. The hook is called with two parameters
Expand Down Expand Up @@ -48,17 +61,6 @@ set -euo pipefail
# pushing anything. Information about why the push is rejected may be
# sent to the user by writing to standard error.

# If pushing a tag, generate doc and push them as
# a "docs" branch in the remote.
case "$LOCAL_REF" in
refs\/tags*)
# Apply specific code when publishing tags
IS_TAG=1;;
*)
# Apply specific code when publishing any branch
IS_TAG=0;;
esac

# We currently use this hook to verify that any commit (to any branch)
# passes the tests configured.
# If a tag is being pushed, then, we generate the documentation
Expand Down
6 changes: 3 additions & 3 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env sh

# Load husky
. "$(dirname -- "$0")/_/husky.sh"
. "$(dirname -- "$0")/_/husky.sh";

# Read parameters
COMMIT_MSG_FILE=$1;
COMMIT_SOURCE=$2;
SHA1=$3;

# Set failing on command fail, pipe fail, and undefined variable use
set -euo pipefail
set -eu;

# This hook is invoked by git-commit right after preparing
# the default log message, and before the editor is started.
Expand Down Expand Up @@ -45,7 +45,7 @@ echo "**************************";
echo "";

# Check if we are doing an amend
if [ "$COMMIT_SOURCE" = 'commit' ] && [ -n $SHA1 ]; then
if [ "$COMMIT_SOURCE" = 'commit' ] && [ -n "$SHA1" ]; then
# Amends do not call the "cz" command.
exit 0;
fi
Expand Down

0 comments on commit 690f2ab

Please sign in to comment.