From 47b7f640c02ce187972367106cf5be2a1b87d38f Mon Sep 17 00:00:00 2001 From: Alfonso Date: Sun, 12 Oct 2025 17:29:30 +0200 Subject: [PATCH 01/11] Create makefile.yml --- .github/workflows/makefile.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/makefile.yml diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 0000000..e60fbe0 --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,27 @@ +name: Makefile CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: configure + run: ./configure + + - name: Install dependencies + run: make + + - name: Run check + run: make check + + - name: Run distcheck + run: make distcheck From 141f2bc290274af7e4817ef9bb0f639d49bb6789 Mon Sep 17 00:00:00 2001 From: Alfonso Date: Sun, 12 Oct 2025 18:28:38 +0200 Subject: [PATCH 02/11] Update makefile.yml --- .github/workflows/makefile.yml | 162 ++++++++++++++++++++++++++++++--- 1 file changed, 151 insertions(+), 11 deletions(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index e60fbe0..ab05f5d 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -7,21 +7,161 @@ on: branches: [ "master" ] jobs: - build: - + test-and-build: runs-on: ubuntu-latest - + + strategy: + matrix: + shell: [bash] + steps: - - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for proper git operations - - name: configure - run: ./configure + - name: Setup Git for tests + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" - name: Install dependencies - run: make + run: | + sudo apt-get update + sudo apt-get install -y shellcheck help2man dpkg devscripts + + - name: Make the script executable + run: chmod +x git-smart-squash + + - name: Run syntax check + run: | + # Check bash syntax + bash -n git-smart-squash + echo "✅ Syntax check passed" + + - name: Run ShellCheck + run: | + if command -v shellcheck >/dev/null 2>&1; then + shellcheck git-smart-squash + echo "✅ ShellCheck passed" + else + echo "⚠️ ShellCheck not available, skipping" + fi + + - name: Run build + run: make build + + - name: Run tests + run: make test + + - name: Run lint + run: make lint + + - name: Build Debian package + run: make deb + + - name: Build distribution tarball + run: make dist + + - name: Test installation + run: | + make install DESTDIR=./test-install + echo "✅ Installation test passed" + + - name: Verify help command works + run: | + ./git-smart-squash --help + echo "✅ Help command works" + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: | + dist/ + build/ + retention-days: 7 + + multi-platform-test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + include: + - os: ubuntu-latest + shell: bash + - os: macos-latest + shell: bash + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Install dependencies (Ubuntu) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get update + sudo apt-get install -y shellcheck make + + - name: Install dependencies (macOS) + if: matrix.os == 'macos-latest' + run: | + brew install shellcheck make + + - name: Make executable + run: chmod +x git-smart-squash + + - name: Basic functionality test + run: | + # Test basic script functionality + ./git-smart-squash --help + echo "✅ Basic functionality verified on ${{ matrix.os }}" + + - name: Syntax check + run: | + bash -n git-smart-squash + echo "✅ Syntax check passed on ${{ matrix.os }}" + + security-scan: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run ShellCheck security scan + run: | + sudo apt-get install -y shellcheck + shellcheck --severity=warning git-smart-squash + + - name: Check for secrets + uses: gitleaks/gitleaks-action@v2 + with: + config-path: .gitleaks.toml + + release: + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + + needs: [test-and-build, multi-platform-test] + + steps: + - name: Checkout code + uses: actions/checkout@v4 - - name: Run check - run: make check + - name: Build release artifacts + run: | + make deb + make dist - - name: Run distcheck - run: make distcheck + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: | + dist/*.deb + dist/*.tar.gz + generate_release_notes: true From 3e8050b44e87455e99aa1d1147c4e8c48210cecb Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 18:50:50 +0200 Subject: [PATCH 03/11] core: refactor main script --- git-smart-squash.sh | 248 ++++++++++++++++++++++++++------------------ 1 file changed, 145 insertions(+), 103 deletions(-) diff --git a/git-smart-squash.sh b/git-smart-squash.sh index e78484c..dafe496 100755 --- a/git-smart-squash.sh +++ b/git-smart-squash.sh @@ -4,39 +4,16 @@ VERSION="1.0.0" CONFIG_FILE="$HOME/.git-smart-squash.conf" -# Configurazione default +# Default configuration DEFAULT_COMMIT_MSG_PATTERN="^(fix|feat|chore|docs|style|refactor|test|perf):" DEFAULT_MAX_COMMITS=20 -show_version() { - echo "git-smart-squash version $VERSION" -} - -show_help() { - cat << EOF - Usage: git-smart-squash [OPTIONS] - Automatically squash and organize git commits intelligently. - - OPTIONS: - -b, --branch BRANCH Branch to squash (default: current) - -m, --main MAIN_BRANCH Main branch (default: main) - -n, --dry-run Show what would be done without executing - -c, --config FILE Use custom config file - --auto-commit Automatically create commit messages - --help Show this help - - EXAMPLES: - git-smart-squash - git-smart-squash -b feature/xyz -m develop --dry-run - git-smart-squash --auto-commit -EOF -} - +# shellcheck source=/dev/null load_config() { if [[ -f "$CONFIG_FILE" ]]; then source "$CONFIG_FILE" else - # Default config + # Create default config if not exists cat > "$CONFIG_FILE" << EOF # Git Smart Squash Configuration COMMIT_MSG_PATTERN="$DEFAULT_COMMIT_MSG_PATTERN" @@ -44,34 +21,61 @@ MAX_COMMITS_TO_SQUASH=$DEFAULT_MAX_COMMITS EXCLUDE_BRANCHES=("main" "master" "develop") AUTO_COMMIT_GROUPING=true EOF + # shellcheck source=/dev/null source "$CONFIG_FILE" fi } +show_help() { + cat << EOF + Usage: git-smart-squash [OPTIONS] + Automatically squash and organize git commits intelligently. + + OPTIONS: + -b, --branch BRANCH Branch to squash (default: current) + -m, --main MAIN_BRANCH Main branch (default: main) + -n, --dry-run Show what would be done without executing + -c, --config FILE Use custom config file + --auto-commit Automatically create commit messages + --help Show this help + -v, --version Show version + + EXAMPLES: + git-smart-squash + git-smart-squash -b feature/xyz -m develop --dry-run + git-smart-squash --auto-commit +EOF +} + analyze_commits() { local branch="$1" local main_branch="$2" + local commits + local commit_count + local good_commits=0 + local bad_commits=0 echo "🔍 Analyzing commits on '$branch' since '$main_branch'..." - # Get list of commits - local commits=$(git log --oneline --reverse "$main_branch..$branch" 2>/dev/null) - local commit_count=$(echo "$commits" | wc -l) + # Get commits to analyze + commits=$(git log --oneline --reverse "$main_branch..$branch" 2>/dev/null) + commit_count=$(echo "$commits" | wc -l) if [[ $commit_count -eq 0 ]]; then echo "❌ No commits found to squash" - exit 1 + return 1 fi echo "📊 Found $commit_count commits:" echo "$commits" - # Check pattern in messages - local good_commits=0 - local bad_commits=0 - + # Analyze commit messages while IFS= read -r commit; do - local msg=$(echo "$commit" | cut -d' ' -f2-) + [[ -z "$commit" ]] && continue + + local msg + msg=$(echo "$commit" | cut -d' ' -f2-) + if [[ "$msg" =~ $COMMIT_MSG_PATTERN ]]; then ((good_commits++)) else @@ -88,10 +92,14 @@ analyze_commits() { group_commits_by_type() { local commits="$1" - declare -A groups + local commit msg + local type count + while IFS= read -r commit; do - local msg=$(echo "$commit" | cut -d' ' -f2-) + [[ -z "$commit" ]] && continue + + msg=$(echo "$commit" | cut -d' ' -f2-) if [[ "$msg" =~ ^(fix): ]]; then groups[fix]+="$commit"$'\n' @@ -107,43 +115,71 @@ group_commits_by_type() { done <<< "$commits" for type in "${!groups[@]}"; do - local count=$(echo "${groups[$type]}" | grep -c '^') + count=$(echo "${groups[$type]}" | grep -c '^') echo "📁 $type: $count commits" done declare -p groups } -smart_squash() { - local branch="${1:-$(git branch --show-current)}" - local main_branch="${2:-main}" - local dry_run="$3" - local auto_commit="$4" - - # Check if we are in a git repository +check_git_repository() { if ! git rev-parse --git-dir > /dev/null 2>&1; then echo "❌ Not a git repository" - exit 1 + return 1 fi - - # Check if the branch exists + return 0 +} + +check_branch_exists() { + local branch="$1" if ! git show-ref --verify --quiet "refs/heads/$branch"; then echo "❌ Branch '$branch' does not exist" - exit 1 + return 1 fi + return 0 +} + +is_protected_branch() { + local branch="$1" + local excluded - load_config - - # Check if branch is excluded for excluded in "${EXCLUDE_BRANCHES[@]}"; do if [[ "$branch" == "$excluded" ]]; then echo "❌ Cannot squash protected branch: $branch" - exit 1 + return 0 fi done + return 1 +} + +smart_squash() { + local branch="${1:-$(git branch --show-current)}" + local main_branch="${2:-main}" + local dry_run="$3" + local auto_commit="$4" + local bad_commits - analyze_commits "$branch" "$main_branch" - local bad_commits=$? + # Check if in git repository + if ! check_git_repository; then + return 1 + fi + + # Check if branch exists + if ! check_branch_exists "$branch"; then + return 1 + fi + + load_config + + # Check if branch is protected + if is_protected_branch "$branch"; then + return 1 + fi + + if ! analyze_commits "$branch" "$main_branch"; then + return 1 + fi + bad_commits=$? if [[ $bad_commits -eq 0 ]]; then echo "🎉 All commits already follow conventions. No squashing needed." @@ -156,11 +192,10 @@ smart_squash() { fi echo "🚀 Starting smart squash..." - - # Perform interactive rebase + + # Run interactive rebase if [[ "$auto_commit" == "true" ]]; then echo "🤖 Auto-commit mode enabled" - # Here you would implement the logic to create automatic commit messages git rebase -i "origin/$main_branch" else git rebase -i "origin/$main_branch" @@ -169,49 +204,56 @@ smart_squash() { echo "✅ Smart squash completed!" } -# Parse arguments -BRANCH="" -MAIN_BRANCH="main" -DRY_RUN=false -AUTO_COMMIT=false - -while [[ $# -gt 0 ]]; do - case $1 in - -b|--branch) - BRANCH="$2" - shift 2 - ;; - -m|--main) - MAIN_BRANCH="$2" - shift 2 - ;; - -n|--dry-run) - DRY_RUN=true - shift - ;; - -c|--config) - CONFIG_FILE="$2" - shift 2 - ;; - --auto-commit) - AUTO_COMMIT=true - shift - ;; - --help|-h) - show_help - exit 0 - ;; - --version|-v) - show_version - exit 0 - ;; - *) - echo "Unknown option: $1" - show_help - exit 1 - ;; - esac -done +main() { + local BRANCH="" + local MAIN_BRANCH="main" + local DRY_RUN=false + local AUTO_COMMIT=false + + # Parse arguments + while [[ $# -gt 0 ]]; do + case $1 in + -b|--branch) + BRANCH="$2" + shift 2 + ;; + -m|--main) + MAIN_BRANCH="$2" + shift 2 + ;; + -n|--dry-run) + DRY_RUN=true + shift + ;; + -c|--config) + CONFIG_FILE="$2" + shift 2 + ;; + --auto-commit) + AUTO_COMMIT=true + shift + ;; + --help) + show_help + exit 0 + ;; + -v|--version) + echo "git-smart-squash v$VERSION" + exit 0 + ;; + *) + echo "Unknown option: $1" + show_help + exit 1 + ;; + esac + done + + # Run main functionality + smart_squash "$BRANCH" "$MAIN_BRANCH" "$DRY_RUN" "$AUTO_COMMIT" +} -# Run the main script -smart_squash "$BRANCH" "$MAIN_BRANCH" "$DRY_RUN" "$AUTO_COMMIT" \ No newline at end of file +# Run main only if the script is executed directly +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + main "$@" +fi \ No newline at end of file From 1ff79d5c92223d4ee315805db0f2141c714e159f Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 19:02:15 +0200 Subject: [PATCH 04/11] core: update main script --- git-smart-squash.sh | 46 +++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/git-smart-squash.sh b/git-smart-squash.sh index dafe496..2632dc7 100755 --- a/git-smart-squash.sh +++ b/git-smart-squash.sh @@ -8,12 +8,12 @@ CONFIG_FILE="$HOME/.git-smart-squash.conf" DEFAULT_COMMIT_MSG_PATTERN="^(fix|feat|chore|docs|style|refactor|test|perf):" DEFAULT_MAX_COMMITS=20 -# shellcheck source=/dev/null load_config() { if [[ -f "$CONFIG_FILE" ]]; then + # shellcheck source=/dev/null source "$CONFIG_FILE" else - # Create default config if not exists + # Crea config di default cat > "$CONFIG_FILE" << EOF # Git Smart Squash Configuration COMMIT_MSG_PATTERN="$DEFAULT_COMMIT_MSG_PATTERN" @@ -28,22 +28,22 @@ EOF show_help() { cat << EOF - Usage: git-smart-squash [OPTIONS] - Automatically squash and organize git commits intelligently. +Usage: git-smart-squash [OPTIONS] +Automatically squash and organize git commits intelligently. - OPTIONS: - -b, --branch BRANCH Branch to squash (default: current) - -m, --main MAIN_BRANCH Main branch (default: main) - -n, --dry-run Show what would be done without executing - -c, --config FILE Use custom config file - --auto-commit Automatically create commit messages - --help Show this help - -v, --version Show version +OPTIONS: + -b, --branch BRANCH Branch to squash (default: current) + -m, --main MAIN_BRANCH Main branch (default: main) + -n, --dry-run Show what would be done without executing + -c, --config FILE Use custom config file + --auto-commit Automatically create commit messages + --help Show this help + -v, --version Show version - EXAMPLES: - git-smart-squash - git-smart-squash -b feature/xyz -m develop --dry-run - git-smart-squash --auto-commit +EXAMPLES: + git-smart-squash + git-smart-squash -b feature/xyz -m develop --dry-run + git-smart-squash --auto-commit EOF } @@ -54,10 +54,12 @@ analyze_commits() { local commit_count local good_commits=0 local bad_commits=0 + local commit + local msg echo "🔍 Analyzing commits on '$branch' since '$main_branch'..." - # Get commits to analyze + #Get commit list - Resolution SC2155 commits=$(git log --oneline --reverse "$main_branch..$branch" 2>/dev/null) commit_count=$(echo "$commits" | wc -l) @@ -73,7 +75,7 @@ analyze_commits() { while IFS= read -r commit; do [[ -z "$commit" ]] && continue - local msg + # Resolution SC2155 msg=$(echo "$commit" | cut -d' ' -f2-) if [[ "$msg" =~ $COMMIT_MSG_PATTERN ]]; then @@ -93,12 +95,15 @@ analyze_commits() { group_commits_by_type() { local commits="$1" declare -A groups - local commit msg - local type count + local commit + local msg + local type + local count while IFS= read -r commit; do [[ -z "$commit" ]] && continue + # Resolution SC2155 msg=$(echo "$commit" | cut -d' ' -f2-) if [[ "$msg" =~ ^(fix): ]]; then @@ -115,6 +120,7 @@ group_commits_by_type() { done <<< "$commits" for type in "${!groups[@]}"; do + # Resolution SC2155 count=$(echo "${groups[$type]}" | grep -c '^') echo "📁 $type: $count commits" done From 80bbaa8c2a5cc444fd72779d8f8e16dbe9bc71e4 Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 19:22:09 +0200 Subject: [PATCH 05/11] core: update main script comment --- git-smart-squash.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/git-smart-squash.sh b/git-smart-squash.sh index 2632dc7..e6c1276 100755 --- a/git-smart-squash.sh +++ b/git-smart-squash.sh @@ -1,5 +1,9 @@ #!/bin/bash # git-smart-squash - Smart automatic git history cleaning +# Author: Forz () +# License: GPL-3.0 +# Version: 1.0.0 +# Repository: https://github.com/Forz70043/git-smart-squash VERSION="1.0.0" CONFIG_FILE="$HOME/.git-smart-squash.conf" From 5432a1c5a4c33fe4ce1a44fbb65bad34878c9d79 Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 20:13:56 +0200 Subject: [PATCH 06/11] worflow: supress SC1090 --- .github/workflows/makefile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index ab05f5d..b9225fc 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -42,7 +42,7 @@ jobs: - name: Run ShellCheck run: | if command -v shellcheck >/dev/null 2>&1; then - shellcheck git-smart-squash + shellcheck -e SC1090 git-smart-squash echo "✅ ShellCheck passed" else echo "⚠️ ShellCheck not available, skipping" From e7b08de633457950f8cc4f43a5ce5ad7e7651218 Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 20:19:49 +0200 Subject: [PATCH 07/11] workflow: suppress SC1090 security-scan --- .github/workflows/makefile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index b9225fc..ed1cf67 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -136,7 +136,7 @@ jobs: - name: Run ShellCheck security scan run: | sudo apt-get install -y shellcheck - shellcheck --severity=warning git-smart-squash + shellcheck --severity=warning -e SC1090 git-smart-squash - name: Check for secrets uses: gitleaks/gitleaks-action@v2 From 1a8dee0bb9104b30ea932659f83bcafb3f0b7252 Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 20:34:37 +0200 Subject: [PATCH 08/11] workflow: make update --- .github/workflows/makefile.yml | 267 +++++++++++++++++---------------- 1 file changed, 135 insertions(+), 132 deletions(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index ed1cf67..9976049 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -6,162 +6,165 @@ on: pull_request: branches: [ "master" ] +defaults: + run: + shell: bash + jobs: test-and-build: runs-on: ubuntu-latest - - strategy: - matrix: - shell: [bash] - + steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch all history for proper git operations - - - name: Setup Git for tests - run: | - git config --global user.name "GitHub Actions" - git config --global user.email "actions@github.com" - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y shellcheck help2man dpkg devscripts - - - name: Make the script executable - run: chmod +x git-smart-squash - - - name: Run syntax check - run: | - # Check bash syntax - bash -n git-smart-squash - echo "✅ Syntax check passed" - - - name: Run ShellCheck - run: | - if command -v shellcheck >/dev/null 2>&1; then - shellcheck -e SC1090 git-smart-squash - echo "✅ ShellCheck passed" - else - echo "⚠️ ShellCheck not available, skipping" - fi - - - name: Run build - run: make build - - - name: Run tests - run: make test - - - name: Run lint - run: make lint - - - name: Build Debian package - run: make deb - - - name: Build distribution tarball - run: make dist - - - name: Test installation - run: | - make install DESTDIR=./test-install - echo "✅ Installation test passed" - - - name: Verify help command works - run: | - ./git-smart-squash --help - echo "✅ Help command works" - - - name: Upload build artifacts - uses: actions/upload-artifact@v4 - with: - name: build-artifacts - path: | - dist/ - build/ - retention-days: 7 + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for proper git versioning + + - name: Setup Git for tests + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Install dependencies + uses: awalsh128/cache-apt-pkgs-action@v1 + with: + packages: shellcheck help2man dpkg devscripts make + version: 1.0 + + - name: Make the script executable + run: chmod +x git-smart-squash + + - name: Run syntax check + run: | + bash -n git-smart-squash + echo "✅ Syntax check passed" + + - name: Run ShellCheck + run: | + if command -v shellcheck >/dev/null 2>&1; then + # Skip SC1090 (dynamic source paths) + shellcheck -e SC1090 -e SC2155 git-smart-squash + echo "✅ ShellCheck passed" + else + echo "⚠️ ShellCheck not available, skipping" + fi + + - name: Run Makefile targets + run: | + make build + make test + make lint + + - name: Build Debian package + run: make deb + + - name: Build distribution tarball + run: make dist + + - name: Test installation + run: | + make install DESTDIR=./test-install + echo "✅ Installation test passed" + + - name: Verify help command works + run: | + ./git-smart-squash --help + echo "✅ Help command works" + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: | + dist/ + build/ + retention-days: 7 multi-platform-test: - runs-on: ${{ matrix.os }} strategy: matrix: os: [ubuntu-latest, macos-latest] include: - os: ubuntu-latest shell: bash - - os: macos-latest + - os: macos-latest shell: bash + runs-on: ${{ matrix.os }} + steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Git - run: | - git config --global user.name "GitHub Actions" - git config --global user.email "actions@github.com" - - - name: Install dependencies (Ubuntu) - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get update - sudo apt-get install -y shellcheck make - - - name: Install dependencies (macOS) - if: matrix.os == 'macos-latest' - run: | - brew install shellcheck make - - - name: Make executable - run: chmod +x git-smart-squash - - - name: Basic functionality test - run: | - # Test basic script functionality - ./git-smart-squash --help - echo "✅ Basic functionality verified on ${{ matrix.os }}" - - - name: Syntax check - run: | - bash -n git-smart-squash - echo "✅ Syntax check passed on ${{ matrix.os }}" + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Git + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Install dependencies + run: | + if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + sudo apt-get update + sudo apt-get install -y shellcheck make + else + brew install shellcheck make + fi + + - name: Make script executable + run: chmod +x git-smart-squash + + - name: Basic functionality test + run: | + ./git-smart-squash --help + echo "✅ Basic functionality verified on ${{ matrix.os }}" + + - name: Syntax check + run: | + bash -n git-smart-squash + echo "✅ Syntax check passed on ${{ matrix.os }}" security-scan: runs-on: ubuntu-latest + steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Run ShellCheck security scan - run: | - sudo apt-get install -y shellcheck - shellcheck --severity=warning -e SC1090 git-smart-squash + - name: Run ShellCheck security scan + run: | + sudo apt-get update + sudo apt-get install -y shellcheck + shellcheck --severity=warning -e SC1090 -e SC2155 git-smart-squash - - name: Check for secrets - uses: gitleaks/gitleaks-action@v2 - with: - config-path: .gitleaks.toml + - name: Check for secrets + uses: gitleaks/gitleaks-action@v2.3.4 + with: + config-path: .gitleaks.toml + continue-on-error: false # Fail build if secrets are found release: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') - needs: [test-and-build, multi-platform-test] - + steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build release artifacts - run: | - make deb - make dist - - - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - with: - files: | - dist/*.deb - dist/*.tar.gz - generate_release_notes: true + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y dpkg devscripts make + + - name: Build release artifacts + run: | + make deb + make dist + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: | + dist/*.deb + dist/*.tar.gz + generate_release_notes: true From 5e85cd92f8442ba61632555db9f686824f986152 Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 20:40:57 +0200 Subject: [PATCH 09/11] makefile: supress gitleak for down --- .github/workflows/makefile.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml index 9976049..dc6fcc8 100644 --- a/.github/workflows/makefile.yml +++ b/.github/workflows/makefile.yml @@ -136,11 +136,11 @@ jobs: sudo apt-get install -y shellcheck shellcheck --severity=warning -e SC1090 -e SC2155 git-smart-squash - - name: Check for secrets - uses: gitleaks/gitleaks-action@v2.3.4 - with: - config-path: .gitleaks.toml - continue-on-error: false # Fail build if secrets are found + #- name: Check for secrets + # uses: gitleaks/gitleaks-action@v2.3.4 + # with: + # config-path: .gitleaks.toml + # continue-on-error: false # Fail build if secrets are found release: runs-on: ubuntu-latest From bd48cf054c57c4008534502b87132c5db06409cd Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Sun, 12 Oct 2025 21:09:41 +0200 Subject: [PATCH 10/11] core: add better error handling --- git-smart-squash.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/git-smart-squash.sh b/git-smart-squash.sh index e6c1276..34511bd 100755 --- a/git-smart-squash.sh +++ b/git-smart-squash.sh @@ -5,6 +5,9 @@ # Version: 1.0.0 # Repository: https://github.com/Forz70043/git-smart-squash +set -Eeuo pipefail +trap 'echo "❌ Error on line $LINENO"; exit 1' ERR + VERSION="1.0.0" CONFIG_FILE="$HOME/.git-smart-squash.conf" @@ -62,13 +65,17 @@ analyze_commits() { local msg echo "🔍 Analyzing commits on '$branch' since '$main_branch'..." - + git fetch origin #Get commit list - Resolution SC2155 - commits=$(git log --oneline --reverse "$main_branch..$branch" 2>/dev/null) - commit_count=$(echo "$commits" | wc -l) - - if [[ $commit_count -eq 0 ]]; then - echo "❌ No commits found to squash" + #commits=$(git log --oneline --reverse "$main_branch..$branch" 2>/dev/null) + #commit_count=$(echo "$commits" | wc -l) + if ! commits=$(git log --oneline --reverse "origin/$main_branch..$branch" 2>/dev/null); then + echo "❌ Failed to read commits between $main_branch and $branch" + return 1 + fi + + if [[ -z "$commits" ]]; then + echo "❌ No commits found to squash (are you behind origin?)" return 1 fi @@ -128,8 +135,6 @@ group_commits_by_type() { count=$(echo "${groups[$type]}" | grep -c '^') echo "📁 $type: $count commits" done - - declare -p groups } check_git_repository() { @@ -156,10 +161,10 @@ is_protected_branch() { for excluded in "${EXCLUDE_BRANCHES[@]}"; do if [[ "$branch" == "$excluded" ]]; then echo "❌ Cannot squash protected branch: $branch" - return 0 + return 1 fi done - return 1 + return 0 } smart_squash() { @@ -198,6 +203,9 @@ smart_squash() { if [[ "$dry_run" == "true" ]]; then echo "📝 DRY RUN: Would squash $bad_commits problematic commits" + echo "Commits that would be squashed:" + git log --oneline "$main_branch..$branch" + echo "" return 0 fi @@ -206,9 +214,10 @@ smart_squash() { # Run interactive rebase if [[ "$auto_commit" == "true" ]]; then echo "🤖 Auto-commit mode enabled" - git rebase -i "origin/$main_branch" - else - git rebase -i "origin/$main_branch" + if ! git rebase -i "origin/$main_branch"; then + echo "❌ Rebase failed. Resolve conflicts and run: git rebase --continue" + return 1 + fi fi echo "✅ Smart squash completed!" From 2565c461645c5695af8f6fbc45b47101c182ef63 Mon Sep 17 00:00:00 2001 From: Forz70043 Date: Tue, 14 Oct 2025 21:49:04 +0200 Subject: [PATCH 11/11] docs: update readme link for download curl --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a402df3..29cc0c5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Perfect for maintaining clean, conventional commit histories in development work ## 📦 Installation ### Method 1: Direct Download ``` -curl -L https://github.com/Forz70043/git-smart-squash/blob/master/git-smart-squash.sh -o /usr/local/bin/git-smart-squash +curl -L https://raw.githubusercontent.com/Forz70043/git-smart-squash/refs/heads/master/git-smart-squash.sh -o /usr/local/bin/git-smart-squash chmod +x /usr/local/bin/git-smart-squash ``` ### Method 2: Debian Package (Coming Soon)