Skip to content

Commit

Permalink
Updated post-commit and post-rewrite hooks to make sure that tarball …
Browse files Browse the repository at this point in the history
…is generated only when underlying files are modified
  • Loading branch information
sanyamsinghal committed May 14, 2024
1 parent fef8873 commit 36f3dcf
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions setup/hooks/post-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ if [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ]; then
exit 0
fi

# Function to check if tarball is up to date
is_up_to_date() {
if [ ! -f "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1
fi

for file in $(find "$REPO_ROOT/$PARENT_DIR/$DIR_NAME" -type f); do
if [ "$file" -nt "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1 # Needs update
fi
done

return 0 # No update needed
}

if is_up_to_date; then
echo "No changes detected, tarball is up to date."
exit 0
fi

pushd "$REPO_ROOT/$PARENT_DIR" > /dev/null
tar -czf "$REPO_ROOT/$OUTPUT_TAR" $DIR_NAME
popd > /dev/null
Expand Down
20 changes: 20 additions & 0 deletions setup/hooks/post-rewrite
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ DIR_NAME="gather-assessment-metadata"
OUTPUT_TAR="yb-voyager/src/srcdb/data/gather-assessment-metadata.tar.gz"
REPO_ROOT=$(git rev-parse --show-toplevel)

# Function to check if tarball is up to date
is_up_to_date() {
if [ ! -f "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1
fi

for file in $(find "$REPO_ROOT/$PARENT_DIR/$DIR_NAME" -type f); do
if [ "$file" -nt "$REPO_ROOT/$OUTPUT_TAR" ]; then
return 1 # Needs update
fi
done

return 0 # No update needed
}

if is_up_to_date; then
echo "No changes detected, tarball is up to date."
exit 0
fi

pushd "$REPO_ROOT/$PARENT_DIR" > /dev/null
tar -czf "$REPO_ROOT/$OUTPUT_TAR" $DIR_NAME
popd > /dev/null
Expand Down

0 comments on commit 36f3dcf

Please sign in to comment.