Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/task_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Shell Script Linter

on:
push:
branches:
- new-branch # This condition makes it run only on the "new-branch"

jobs:
shellcheck:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run Shellcheck on Bash scripts
uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
reporter: github-pr-review
shellcheck_flags: 'task_tester.sh hooks/pre-commit hooks/post-commit'
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Secrets and keys
deploy_key
deploy_key.pub

# Hook generated local artifacts (do not track)


# OS / editor
.DS_Store
Thumbs.db
*.log
*.swp
.vscode/
.idea/
node_modules/
.env
15 changes: 15 additions & 0 deletions IIT2024003/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Secrets and keys
deploy_key
deploy_key.pub

# Hook generated local artifacts (do not track)

# OS / editor-specific files
.DS_Store
Thumbs.db
*.log
*.swp
.vscode/
.idea/
node_modules/
.env
6 changes: 6 additions & 0 deletions IIT2024003/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Your Name": "Rajan Patil",
"Your Roll Number": "IIT2024003",
"Your Email": "[email protected]",
"GitHub Repository Link": "https://github.com/RajanPatil1904/fossProject"
}
92 changes: 92 additions & 0 deletions IIT2024003/task_tester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# ANSI color codes for fun and colorful output
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Print script header
echo -e "${BLUE}Git Hooks Testing Script${NC}"
echo -e "${BLUE}-------------------------${NC}"
echo -e "${BLUE}This script will test the functionality of your Git hooks.${NC}"
echo -e "${BLUE}Make sure you have committed all your changes before running this test.${NC}"
echo -e ""

# --- Check for Hooks Directory ---
echo -e "${BLUE}Checking Hooks Directory${NC}"
if [ -d "hooks" ]; then
echo -e "${GREEN}[SUCCESS] Hooks directory found.${NC}"
if [ -f "hooks/pre-commit" ] && [ -f "hooks/post-commit" ]; then
echo -e "${GREEN}[SUCCESS] Pre-commit and post-commit hooks found.${NC}"
else
echo -e "${RED}[ERROR] Pre-commit or post-commit hook files are missing.${NC}"
exit 1
fi
else
echo -e "${RED}[ERROR] 'hooks' directory not found. Please create it and add your hooks inside.${NC}"
exit 1
fi
echo -e ""

# --- Install Hooks ---
echo -e "${BLUE}Installing Hooks${NC}"
echo -e "${BLUE}[INFO] Installing pre-commit and post-commit hooks...${NC}"
cp hooks/pre-commit .git/hooks/pre-commit
cp hooks/post-commit .git/hooks/post-commit
chmod +x .git/hooks/pre-commit .git/hooks/post-commit
echo -e "${GREEN}[SUCCESS] Hooks installed successfully.${NC}"
echo -e ""

# --- Test Pre-commit Security Check ---
echo -e "${BLUE}Testing Pre-commit Security Check${NC}"
echo -e "${BLUE}[INFO] Creating a file with sensitive information...${NC}"
echo -e "${YELLOW}warning: in the working copy of 'test_security.txt', LF will be replaced by CRLF the next time Git touches it${NC}"
echo "This is a dummy file with a sensitive keyword like deploy_key.pub" > test_security.txt
git add test_security.txt
echo -e "${BLUE}[INFO] Attempting to commit a file with a sensitive keyword...${NC}"
if ! git commit -m "Attempting to commit a file with a sensitive keyword"; then
echo -e "${GREEN}[SUCCESS] Pre-commit security check successfully blocked the commit containing sensitive information.${NC}"
else
echo -e "${RED}[ERROR] Pre-commit security check failed. The sensitive file was committed.${NC}"
fi
git reset HEAD test_security.txt
rm test_security.txt
echo -e "${BLUE}[INFO] Cleaned up security test file.${NC}"
echo -e ""

# --- Test Regular Commit Workflow ---
echo -e "${BLUE}Testing Regular Commit Workflow${NC}"
echo -e "${BLUE}[INFO] Creating a test file for commit...${NC}"
echo -e "${YELLOW}warning: in the working copy of 'test_commit.txt', LF will be replaced by CRLF the next time Git touches it${NC}"
echo "This is a normal test file." > test_commit.txt
git add test_commit.txt
echo -e "${BLUE}[INFO] Attempting to commit a normal file...${NC}"
if git commit -m "Test commit to trigger hooks"; then
echo -e "${GREEN}[SUCCESS] Regular commit succeeded, pre-commit hook passed.${NC}"
if [ -f "task_commands.sh" ] && [ -f "commit_details.txt" ]; then
echo -e "${GREEN}[SUCCESS] Post-commit hook successfully recorded commit details.${NC}"
else
echo -e "${RED}[ERROR] Post-commit hook failed to create the required files.${NC}"
fi
else
echo -e "${RED}[ERROR] The pre-commit hook failed unexpectedly on a normal file.${NC}"
fi
echo -e ""

# --- Cleaning Up ---
echo -e "${BLUE}Cleaning Up${NC}"
echo -e "${BLUE}[INFO] Cleaning up test files and commits...${NC}"
rm test_security.txt > /dev/null 2>&1
rm test_commit.txt > /dev/null 2>&1
git reset HEAD^ --hard

echo -e "${GREEN}[SUCCESS] Removed test files.${NC}"
echo -e "${GREEN}[SUCCESS] Reverted test commit.${NC}"
echo -e ""

# --- Test Summary ---
echo -e "${BLUE}Test Summary${NC}"
echo -e "-------------------------"
echo -e "${GREEN}All tests passed successfully!${NC}"
3 changes: 3 additions & 0 deletions commit_details.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Commit Message: info.json added containing my info
Author Name: Rajan
Author Email: [email protected]
Binary file added result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added task_commands.sh
Empty file.
92 changes: 92 additions & 0 deletions task_tester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# ANSI color codes for fun and colorful output
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Print script header
echo -e "${BLUE}Git Hooks Testing Script${NC}"
echo -e "${BLUE}-------------------------${NC}"
echo -e "${BLUE}This script will test the functionality of your Git hooks.${NC}"
echo -e "${BLUE}Make sure you have committed all your changes before running this test.${NC}"
echo -e ""

# --- Check for Hooks Directory ---
echo -e "${BLUE}Checking Hooks Directory${NC}"
if [ -d "hooks" ]; then
echo -e "${GREEN}[SUCCESS] Hooks directory found.${NC}"
if [ -f "hooks/pre-commit" ] && [ -f "hooks/post-commit" ]; then
echo -e "${GREEN}[SUCCESS] Pre-commit and post-commit hooks found.${NC}"
else
echo -e "${RED}[ERROR] Pre-commit or post-commit hook files are missing.${NC}"
exit 1
fi
else
echo -e "${RED}[ERROR] 'hooks' directory not found. Please create it and add your hooks inside.${NC}"
exit 1
fi
echo -e ""

# --- Install Hooks ---
echo -e "${BLUE}Installing Hooks${NC}"
echo -e "${BLUE}[INFO] Installing pre-commit and post-commit hooks...${NC}"
cp hooks/pre-commit .git/hooks/pre-commit
cp hooks/post-commit .git/hooks/post-commit
chmod +x .git/hooks/pre-commit .git/hooks/post-commit
echo -e "${GREEN}[SUCCESS] Hooks installed successfully.${NC}"
echo -e ""

# --- Test Pre-commit Security Check ---
echo -e "${BLUE}Testing Pre-commit Security Check${NC}"
echo -e "${BLUE}[INFO] Creating a file with sensitive information...${NC}"
echo -e "${YELLOW}warning: in the working copy of 'test_security.txt', LF will be replaced by CRLF the next time Git touches it${NC}"
echo "This is a dummy file with a sensitive keyword like deploy_key.pub" > test_security.txt
git add test_security.txt
echo -e "${BLUE}[INFO] Attempting to commit a file with a sensitive keyword...${NC}"
if ! git commit -m "Attempting to commit a file with a sensitive keyword"; then
echo -e "${GREEN}[SUCCESS] Pre-commit security check successfully blocked the commit containing sensitive information.${NC}"
else
echo -e "${RED}[ERROR] Pre-commit security check failed. The sensitive file was committed.${NC}"
fi
git reset HEAD test_security.txt
rm test_security.txt
echo -e "${BLUE}[INFO] Cleaned up security test file.${NC}"
echo -e ""

# --- Test Regular Commit Workflow ---
echo -e "${BLUE}Testing Regular Commit Workflow${NC}"
echo -e "${BLUE}[INFO] Creating a test file for commit...${NC}"
echo -e "${YELLOW}warning: in the working copy of 'test_commit.txt', LF will be replaced by CRLF the next time Git touches it${NC}"
echo "This is a normal test file." > test_commit.txt
git add test_commit.txt
echo -e "${BLUE}[INFO] Attempting to commit a normal file...${NC}"
if git commit -m "Test commit to trigger hooks"; then
echo -e "${GREEN}[SUCCESS] Regular commit succeeded, pre-commit hook passed.${NC}"
if [ -f "task_commands.sh" ] && [ -f "commit_details.txt" ]; then
echo -e "${GREEN}[SUCCESS] Post-commit hook successfully recorded commit details.${NC}"
else
echo -e "${RED}[ERROR] Post-commit hook failed to create the required files.${NC}"
fi
else
echo -e "${RED}[ERROR] The pre-commit hook failed unexpectedly on a normal file.${NC}"
fi
echo -e ""

# --- Cleaning Up ---
echo -e "${BLUE}Cleaning Up${NC}"
echo -e "${BLUE}[INFO] Cleaning up test files and commits...${NC}"
rm test_security.txt > /dev/null 2>&1
rm test_commit.txt > /dev/null 2>&1
git reset HEAD^ --hard

echo -e "${GREEN}[SUCCESS] Removed test files.${NC}"
echo -e "${GREEN}[SUCCESS] Reverted test commit.${NC}"
echo -e ""

# --- Test Summary ---
echo -e "${BLUE}Test Summary${NC}"
echo -e "-------------------------"
echo -e "${GREEN}All tests passed successfully!${NC}"
1 change: 1 addition & 0 deletions test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test file for hooks.
1 change: 1 addition & 0 deletions test_security.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a dummy file with a sensitive keyword like