Created
January 21, 2025 04:34
-
-
Save isharadilshan/d7f67eef1642456ba8d22f279ed06e01 to your computer and use it in GitHub Desktop.
Line of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Variables | |
start_date="2024-07-01" | |
end_date="2024-07-05" | |
branch="develop" | |
# Checkout branch and pull the latest changes | |
git checkout $branch | |
git pull | |
# Get the commit hashes for the specified dates | |
start_commit=$(git rev-list -n1 --before="$start_date" $branch) | |
end_commit=$(git rev-list -n1 --before="$end_date" $branch) | |
# Path to cloc binary (ensure it is installed via Homebrew or downloaded manually) | |
cloc_path="/usr/local/bin/cloc" | |
# If cloc is not installed, notify the user | |
if ! command -v $cloc_path &>/dev/null; then | |
echo "cloc is not installed. Please install it using 'brew install cloc' or download it from https://github.com/AlDanial/cloc" | |
exit 1 | |
fi | |
# Run cloc with exclusions for React Native project | |
echo "Calculating lines of code changes between $start_commit and $end_commit..." | |
# Exclude directories and languages typically not needed | |
$cloc_path --exclude-dir=test,tests \ | |
--exclude-lang=YAML,SVG,XML \ | |
--git --diff $start_commit $end_commit | |
# Analyze the full repository at the ending commit (optional, for comparison) | |
$cloc_path --exclude-lang=YAML,SVG,XML --git $end_commit | |
# Get number of added, modified, and removed lines using `git diff` | |
echo "Getting detailed line modifications between $start_commit and $end_commit..." | |
# Generate the diff between the two commits and count added, modified, and removed lines | |
added_lines=$(git diff --numstat $start_commit $end_commit | awk '{added+=$1} END {print added}') | |
removed_lines=$(git diff --numstat $start_commit $end_commit | awk '{removed+=$2} END {print removed}') | |
modified_lines=$((added_lines + removed_lines)) | |
echo "Lines added: $added_lines" | |
echo "Lines removed: $removed_lines" | |
echo "Lines modified: $modified_lines" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment