From 5bbde892ba65888b7c652d4b7cbed849c45520be Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Mon, 31 Mar 2025 23:55:08 -0400 Subject: [PATCH 1/8] Adding support for contributing using Windows. --- CONTRIBUTING.md | 11 ++++-- Makefile.win | 51 +++++++++++++++++++++++++++ script/bootstrap.ps1 | 18 ++++++++++ script/ensure-go-installed.ps1 | 64 ++++++++++++++++++++++++++++++++++ script/go.ps1 | 21 +++++++++++ 5 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 Makefile.win create mode 100644 script/bootstrap.ps1 create mode 100644 script/ensure-go-installed.ps1 create mode 100644 script/go.ps1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f4427e8..dfb3a7b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,8 +11,15 @@ Please note that this project is released with a [Contributor Code of Conduct][c ## Submitting a pull request 1. [Fork][fork] and clone the repository -2. Configure and install the dependencies: `script/bootstrap` -3. Make sure the tests pass on your machine: `make test` + + + +2. Configure and install the dependencies + - On Unix-y machines: `script/bootstrap` + - On Windows: `script/bootstrap.ps1` (requires PowerShell 7+) +3. Make sure the tests pass on your machine + - On Unix-y machines: `make test` + - On Windows machines: `make -f Makefile.win test` (because there's a different Makefile when building on Windows) 4. Create a new branch: `git checkout -b my-branch-name` 5. Make your change, add tests, and make sure the tests still pass 6. Push to your fork and [submit a pull request][pr] diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..532a67b --- /dev/null +++ b/Makefile.win @@ -0,0 +1,51 @@ +# Windows-specific Makefile for git-sizer designed for PowerShell + +PACKAGE := github.com/github/git-sizer +GO111MODULES := 1 + +# Use the project's go wrapper script via the -File parameter to avoid loading your profile +GOSCRIPT := $(CURDIR)/script/go.ps1 +# GOSCRIPTCORRECTED := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "$(GOSCRIPT) -replace '/', '\'") +GO := pwsh.exe -NoProfile -ExecutionPolicy Bypass -File $(GOSCRIPT) + +# Get the build version from git using try/catch instead of "||" +BUILD_VERSION := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "try { git describe --tags --always --dirty 2>$null } catch { Write-Output 'unknown' }") +LDFLAGS := -X github.com/github/git-sizer/main.BuildVersion=$(BUILD_VERSION) +GOFLAGS := -mod=readonly + +ifdef USE_ISATTY +GOFLAGS := $(GOFLAGS) --tags isatty +endif + +# Default target +all: bin/git-sizer.exe + +# Main binary target +bin/git-sizer.exe: + @powershell -NoProfile -ExecutionPolicy Bypass -Command "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }" + $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o .\bin\git-sizer.exe . + +# Test target +test: bin/git-sizer.exe gotest + +# Run go tests +gotest: + $(GO) test -timeout 60s $(GOFLAGS) -ldflags "$(LDFLAGS)" ./... + +# Clean up builds +clean: + @powershell -NoProfile -ExecutionPolicy Bypass -Command "if (Test-Path bin) { Remove-Item -Recurse -Force bin }" + +# Help target +help: + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Windows Makefile for git-sizer' -ForegroundColor Cyan" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ''" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Targets:' -ForegroundColor Green" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' all - Build git-sizer (default)'" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' test - Run tests'" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' clean - Clean build artifacts'" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ''" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Example usage:' -ForegroundColor Green" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win'" + @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win test'" + \ No newline at end of file diff --git a/script/bootstrap.ps1 b/script/bootstrap.ps1 new file mode 100644 index 0000000..7f0413a --- /dev/null +++ b/script/bootstrap.ps1 @@ -0,0 +1,18 @@ +#!/usr/bin/env pwsh + +# Exit immediately if any command fails +$ErrorActionPreference = "Stop" + +# Change directory to the parent directory of the script +Set-Location -Path (Split-Path -Parent $PSCommandPath | Split-Path -Parent) + +# Set ROOTDIR environment variable to the current directory +$env:ROOTDIR = (Get-Location).Path + +# Check if the operating system is macOS +if ($IsMacOS) { + brew bundle +} + +# Source the ensure-go-installed.ps1 script +. ./script/ensure-go-installed.ps1 \ No newline at end of file diff --git a/script/ensure-go-installed.ps1 b/script/ensure-go-installed.ps1 new file mode 100644 index 0000000..5479eec --- /dev/null +++ b/script/ensure-go-installed.ps1 @@ -0,0 +1,64 @@ +# This script is meant to be sourced with ROOTDIR set. + +if (-not $env:ROOTDIR) { + Write-Error 'ensure-go-installed.ps1 invoked without ROOTDIR set!' +} + +# Function to check if Go is installed and at least version 1.21 +function GoOk { + $goVersionOutput = & go version 2>$null + if ($goVersionOutput) { + $goVersion = $goVersionOutput -match 'go(\d+)\.(\d+)' | Out-Null + $majorVersion = [int]$Matches[1] + $minorVersion = [int]$Matches[2] + return ($majorVersion -eq 1 -and $minorVersion -ge 21) + } + return $false +} + +# Function to set up a local Go installation if available +function SetUpVendoredGo { + $GO_VERSION = "go1.23.7" + $VENDORED_GOROOT = Join-Path -Path $env:ROOTDIR -ChildPath "vendor/$GO_VERSION/go" + if (Test-Path -Path "$VENDORED_GOROOT/bin/go") { + $env:GOROOT = $VENDORED_GOROOT + $env:PATH = "$env:GOROOT/bin;$env:PATH" + } +} + +# Function to check if Make is installed and install it if needed +function EnsureMakeInstalled { + $makeInstalled = $null -ne (Get-Command "make" -ErrorAction SilentlyContinue) + if (-not $makeInstalled) { + #Write-Host "Installing Make using winget..." + winget install --no-upgrade --nowarn -e --id GnuWin32.Make + if ($LASTEXITCODE -ne 0 -and $LASTEXITCODE -ne 0x8A150061) { + Write-Error "Failed to install Make. Please install it manually. Exit code: $LASTEXITCODE" + } + # Refresh PATH to include the newly installed Make + $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User") + } + + # Add GnuWin32 bin directory directly to the PATH + $gnuWin32Path = "C:\Program Files (x86)\GnuWin32\bin" + if (Test-Path -Path $gnuWin32Path) { + $env:PATH = "$gnuWin32Path;$env:PATH" + } else { + Write-Host "Couldn't find GnuWin32 bin directory at the expected location." + # Also refresh PATH from environment variables as a fallback + $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User") + } +} + +SetUpVendoredGo + +if (-not (GoOk)) { + & ./script/install-vendored-go >$null + if ($LASTEXITCODE -ne 0) { + exit 1 + } + SetUpVendoredGo +} + +# Ensure Make is installed +EnsureMakeInstalled diff --git a/script/go.ps1 b/script/go.ps1 new file mode 100644 index 0000000..e2314b8 --- /dev/null +++ b/script/go.ps1 @@ -0,0 +1,21 @@ +# Ensure that script errors stop execution +$ErrorActionPreference = "Stop" + +# Determine the root directory of the project. +$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path +$ROOTDIR = (Resolve-Path (Join-Path $scriptDir "..")).Path + +# Source the ensure-go-installed functionality. +# (This assumes you have a corresponding PowerShell version of ensure-go-installed. +# If not, you could call the bash version via bash.exe if available.) +$ensureScript = Join-Path $ROOTDIR "script\ensure-go-installed.ps1" +if (Test-Path $ensureScript) { + . $ensureScript +} else { + Write-Error "Unable to locate '$ensureScript'. Please provide a PowerShell version of ensure-go-installed." +} + +# Execute the actual 'go' command with passed arguments. +# This re-invokes the Go tool in PATH. +$goExe = "go" +& $goExe @args \ No newline at end of file From 25b2390918919689421dee37cabee540ae051857 Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Tue, 1 Apr 2025 16:26:43 -0400 Subject: [PATCH 2/8] Added compressed size and updated a few labels. --- Makefile.win | 19 +++++++++++-------- git-sizer.go | 13 +++++++++++++ git/git.go | 7 +++++-- sizes/dirsize.go | 28 ++++++++++++++++++++++++++++ sizes/output.go | 19 +++++++++++++------ sizes/sizes.go | 3 +++ 6 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 sizes/dirsize.go diff --git a/Makefile.win b/Makefile.win index 532a67b..ec6f208 100644 --- a/Makefile.win +++ b/Makefile.win @@ -5,11 +5,10 @@ GO111MODULES := 1 # Use the project's go wrapper script via the -File parameter to avoid loading your profile GOSCRIPT := $(CURDIR)/script/go.ps1 -# GOSCRIPTCORRECTED := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "$(GOSCRIPT) -replace '/', '\'") GO := pwsh.exe -NoProfile -ExecutionPolicy Bypass -File $(GOSCRIPT) # Get the build version from git using try/catch instead of "||" -BUILD_VERSION := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "try { git describe --tags --always --dirty 2>$null } catch { Write-Output 'unknown' }") +BUILD_VERSION := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "try { git describe --tags --always --dirty 2>$$null } catch { Write-Output 'unknown' }") LDFLAGS := -X github.com/github/git-sizer/main.BuildVersion=$(BUILD_VERSION) GOFLAGS := -mod=readonly @@ -17,16 +16,21 @@ ifdef USE_ISATTY GOFLAGS := $(GOFLAGS) --tags isatty endif +# Find all Go source files +GO_SRC_FILES := $(shell powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path . -Filter *.go -Recurse | Select-Object -ExpandProperty FullName") + # Default target all: bin/git-sizer.exe -# Main binary target -bin/git-sizer.exe: +# Main binary target - depend on all Go source files +bin/git-sizer.exe: $(GO_SRC_FILES) @powershell -NoProfile -ExecutionPolicy Bypass -Command "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }" - $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o .\bin\git-sizer.exe . + $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -a -o .\bin\git-sizer.exe . -# Test target -test: bin/git-sizer.exe gotest +# Test target - explicitly run the build first to ensure binary is up to date +test: + @$(MAKE) -f Makefile.win bin/git-sizer.exe + @$(MAKE) -f Makefile.win gotest # Run go tests gotest: @@ -48,4 +52,3 @@ help: @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Example usage:' -ForegroundColor Green" @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win'" @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win test'" - \ No newline at end of file diff --git a/git-sizer.go b/git-sizer.go index 1ef9812..b78dc5f 100644 --- a/git-sizer.go +++ b/git-sizer.go @@ -331,6 +331,19 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st return fmt.Errorf("error scanning repository: %w", err) } + // Calculate the actual size of the .git directory + gitDir, err := repo.GitDir() + if err != nil { + return fmt.Errorf("error getting Git directory path: %w", err) + } + + gitDirSize, err := sizes.CalculateGitDirSize(gitDir) + if err != nil { + return fmt.Errorf("error calculating Git directory size: %w", err) + } + + historySize.GitDirSize = gitDirSize + if jsonOutput { var j []byte var err error diff --git a/git/git.go b/git/git.go index 096ce81..5fc8f34 100644 --- a/git/git.go +++ b/git/git.go @@ -150,8 +150,11 @@ func (repo *Repository) GitCommand(callerArgs ...string) *exec.Cmd { // GitDir returns the path to `repo`'s `GIT_DIR`. It might be absolute // or it might be relative to the current directory. -func (repo *Repository) GitDir() string { - return repo.gitDir +func (repo *Repository) GitDir() (string, error) { + if repo.gitDir == "" { + return "", errors.New("gitDir is not set") + } + return repo.gitDir, nil } // GitPath returns that path of a file within the git repository, by diff --git a/sizes/dirsize.go b/sizes/dirsize.go new file mode 100644 index 0000000..3b60ed2 --- /dev/null +++ b/sizes/dirsize.go @@ -0,0 +1,28 @@ +package sizes + +import ( + "os" + "path/filepath" + + "github.com/github/git-sizer/counts" +) + +// CalculateGitDirSize returns the total size in bytes of the .git directory +func CalculateGitDirSize(gitDir string) (counts.Count64, error) { + var totalSize counts.Count64 + + err := filepath.Walk(gitDir, func(path string, info os.FileInfo, err error) error { + if err != nil { + // Skip files we can't access + return nil + } + + // Only count files, not directories + if !info.IsDir() { + totalSize.Increment(counts.Count64(info.Size())) + } + return nil + }) + + return totalSize, err +} diff --git a/sizes/output.go b/sizes/output.go index 933cc05..0538cb7 100644 --- a/sizes/output.go +++ b/sizes/output.go @@ -279,10 +279,10 @@ func (t *Threshold) Type() string { // A `pflag.Value` that can be used as a boolean option that sets a // `Threshold` variable to a fixed value. For example, // -// pflag.Var( -// sizes.NewThresholdFlagValue(&threshold, 30), -// "critical", "only report critical statistics", -// ) +// pflag.Var( +// sizes.NewThresholdFlagValue(&threshold, 30), +// "critical", "only report critical statistics", +// ) // // adds a `--critical` flag that sets `threshold` to 30. type thresholdFlagValue struct { @@ -492,7 +492,7 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents { return S( "", S( - "Overall repository size", + "Repository statistics", S( "Commits", I("uniqueCommitCount", "Count", @@ -521,11 +521,18 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents { I("uniqueBlobCount", "Count", "The total number of distinct blob objects", nil, s.UniqueBlobCount, metric, "", 1.5e6), - I("uniqueBlobSize", "Total size", + I("uniqueBlobSize", "Uncompressed total size", "The total size of all distinct blob objects", nil, s.UniqueBlobSize, binary, "B", 10e9), ), + S( + "On-disk size", + I("gitDirSize", "Compressed total size", + "The actual on-disk size of the .git directory", + nil, s.GitDirSize, binary, "B", 1e9), + ), + S( "Annotated tags", I("uniqueTagCount", "Count", diff --git a/sizes/sizes.go b/sizes/sizes.go index b3de0bc..4ed115c 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -210,6 +210,9 @@ type HistorySize struct { // The tree with the maximum expanded submodule count. MaxExpandedSubmoduleCountTree *Path `json:"max_expanded_submodule_count_tree,omitempty"` + + // The actual size of the .git directory on disk + GitDirSize counts.Count64 `json:"git_dir_size"` } // Convenience function: forget `*path` if it is non-nil and overwrite From ed4478883f640a350634847723c059b2bd6b2757 Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Wed, 2 Apr 2025 14:20:25 -0400 Subject: [PATCH 3/8] Updating CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dfb3a7b..e0d3b51 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,10 +15,10 @@ Please note that this project is released with a [Contributor Code of Conduct][c 2. Configure and install the dependencies - - On Unix-y machines: `script/bootstrap` + - On Unix-like machines: `script/bootstrap` - On Windows: `script/bootstrap.ps1` (requires PowerShell 7+) 3. Make sure the tests pass on your machine - - On Unix-y machines: `make test` + - On Unix-like machines: `make test` - On Windows machines: `make -f Makefile.win test` (because there's a different Makefile when building on Windows) 4. Create a new branch: `git checkout -b my-branch-name` 5. Make your change, add tests, and make sure the tests still pass From 469485b19698604c0d22ad7560dee4a039ab5e65 Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Wed, 2 Apr 2025 14:44:54 -0400 Subject: [PATCH 4/8] Linter updates. --- git-sizer.go | 4 ++-- sizes/sizes.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/git-sizer.go b/git-sizer.go index b78dc5f..0f44aad 100644 --- a/git-sizer.go +++ b/git-sizer.go @@ -336,12 +336,12 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st if err != nil { return fmt.Errorf("error getting Git directory path: %w", err) } - + gitDirSize, err := sizes.CalculateGitDirSize(gitDir) if err != nil { return fmt.Errorf("error calculating Git directory size: %w", err) } - + historySize.GitDirSize = gitDirSize if jsonOutput { diff --git a/sizes/sizes.go b/sizes/sizes.go index 4ed115c..73834fd 100644 --- a/sizes/sizes.go +++ b/sizes/sizes.go @@ -210,8 +210,8 @@ type HistorySize struct { // The tree with the maximum expanded submodule count. MaxExpandedSubmoduleCountTree *Path `json:"max_expanded_submodule_count_tree,omitempty"` - - // The actual size of the .git directory on disk + + // The actual size of the .git directory on disk. GitDirSize counts.Count64 `json:"git_dir_size"` } From 56839e56669ba8498e3ae5a9eb85033518fec3da Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Wed, 2 Apr 2025 14:49:41 -0400 Subject: [PATCH 5/8] More linter updates. --- git-sizer.go | 2 +- sizes/dirsize.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/git-sizer.go b/git-sizer.go index 0f44aad..fe5876b 100644 --- a/git-sizer.go +++ b/git-sizer.go @@ -331,7 +331,7 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st return fmt.Errorf("error scanning repository: %w", err) } - // Calculate the actual size of the .git directory + // Calculate the actual size of the .git directory. gitDir, err := repo.GitDir() if err != nil { return fmt.Errorf("error getting Git directory path: %w", err) diff --git a/sizes/dirsize.go b/sizes/dirsize.go index 3b60ed2..f490629 100644 --- a/sizes/dirsize.go +++ b/sizes/dirsize.go @@ -7,17 +7,17 @@ import ( "github.com/github/git-sizer/counts" ) -// CalculateGitDirSize returns the total size in bytes of the .git directory +// CalculateGitDirSize returns the total size in bytes of the .git directory. func CalculateGitDirSize(gitDir string) (counts.Count64, error) { var totalSize counts.Count64 err := filepath.Walk(gitDir, func(path string, info os.FileInfo, err error) error { if err != nil { - // Skip files we can't access + // Skip files we can't access. return nil } - // Only count files, not directories + // Only count files, not directories. if !info.IsDir() { totalSize.Increment(counts.Count64(info.Size())) } From 5d3b4abf0a77081573e636daf9083d36e4ecc1ec Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Wed, 2 Apr 2025 14:56:48 -0400 Subject: [PATCH 6/8] Linter updates. --- sizes/dirsize.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sizes/dirsize.go b/sizes/dirsize.go index f490629..eb9eb99 100644 --- a/sizes/dirsize.go +++ b/sizes/dirsize.go @@ -13,8 +13,11 @@ func CalculateGitDirSize(gitDir string) (counts.Count64, error) { err := filepath.Walk(gitDir, func(path string, info os.FileInfo, err error) error { if err != nil { - // Skip files we can't access. - return nil + // Only skip errors for files we cannot access. + if os.IsNotExist(err) || os.IsPermission(err) { + return nil + } + return err } // Only count files, not directories. From f6a16d7b7a0e309f0701519920469fcf41579c62 Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Mon, 7 Apr 2025 14:22:40 -0400 Subject: [PATCH 7/8] Simplified Makefile.win --- Makefile.win | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Makefile.win b/Makefile.win index ec6f208..d37c9d7 100644 --- a/Makefile.win +++ b/Makefile.win @@ -19,36 +19,39 @@ endif # Find all Go source files GO_SRC_FILES := $(shell powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path . -Filter *.go -Recurse | Select-Object -ExpandProperty FullName") +# Define common PowerShell command +PWSH := @powershell -NoProfile -ExecutionPolicy Bypass -Command + # Default target all: bin/git-sizer.exe # Main binary target - depend on all Go source files bin/git-sizer.exe: $(GO_SRC_FILES) - @powershell -NoProfile -ExecutionPolicy Bypass -Command "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }" - $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -a -o .\bin\git-sizer.exe . + $(PWSH) "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }" + $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -a -o .\bin\git-sizer.exe . # Test target - explicitly run the build first to ensure binary is up to date test: - @$(MAKE) -f Makefile.win bin/git-sizer.exe - @$(MAKE) -f Makefile.win gotest + @$(MAKE) -f Makefile.win bin/git-sizer.exe + @$(MAKE) -f Makefile.win gotest # Run go tests gotest: - $(GO) test -timeout 60s $(GOFLAGS) -ldflags "$(LDFLAGS)" ./... + $(GO) test -timeout 60s $(GOFLAGS) -ldflags "$(LDFLAGS)" ./... # Clean up builds clean: - @powershell -NoProfile -ExecutionPolicy Bypass -Command "if (Test-Path bin) { Remove-Item -Recurse -Force bin }" + $(PWSH) "if (Test-Path bin) { Remove-Item -Recurse -Force bin }" # Help target help: - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Windows Makefile for git-sizer' -ForegroundColor Cyan" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ''" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Targets:' -ForegroundColor Green" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' all - Build git-sizer (default)'" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' test - Run tests'" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' clean - Clean build artifacts'" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ''" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Example usage:' -ForegroundColor Green" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win'" - @powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win test'" + $(PWSH) "Write-Host 'Windows Makefile for git-sizer' -ForegroundColor Cyan" + $(PWSH) "Write-Host ''" + $(PWSH) "Write-Host 'Targets:' -ForegroundColor Green" + $(PWSH) "Write-Host ' all - Build git-sizer (default)'" + $(PWSH) "Write-Host ' test - Run tests'" + $(PWSH) "Write-Host ' clean - Clean build artifacts'" + $(PWSH) "Write-Host ''" + $(PWSH) "Write-Host 'Example usage:' -ForegroundColor Green" + $(PWSH) "Write-Host ' nmake -f Makefile.win'" + $(PWSH) "Write-Host ' nmake -f Makefile.win test'" From 5b5042832001ba8a03d17f03d43e5ae40196869d Mon Sep 17 00:00:00 2001 From: Scott Arbeit Date: Mon, 7 Apr 2025 15:04:26 -0400 Subject: [PATCH 8/8] =?UTF-8?q?Repaired=20tabs=20in=20makefile=20?= =?UTF-8?q?=F0=9F=99=84;=20added=20variable=20set=20in=20script.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.win | 32 ++++++++++++++++---------------- script/ensure-go-installed.ps1 | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Makefile.win b/Makefile.win index d37c9d7..b772251 100644 --- a/Makefile.win +++ b/Makefile.win @@ -27,31 +27,31 @@ all: bin/git-sizer.exe # Main binary target - depend on all Go source files bin/git-sizer.exe: $(GO_SRC_FILES) - $(PWSH) "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }" - $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -a -o .\bin\git-sizer.exe . + $(PWSH) "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }" + $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -a -o .\bin\git-sizer.exe . # Test target - explicitly run the build first to ensure binary is up to date test: - @$(MAKE) -f Makefile.win bin/git-sizer.exe - @$(MAKE) -f Makefile.win gotest + @$(MAKE) -f Makefile.win bin/git-sizer.exe + @$(MAKE) -f Makefile.win gotest # Run go tests gotest: - $(GO) test -timeout 60s $(GOFLAGS) -ldflags "$(LDFLAGS)" ./... + $(GO) test -timeout 60s $(GOFLAGS) -ldflags "$(LDFLAGS)" ./... # Clean up builds clean: - $(PWSH) "if (Test-Path bin) { Remove-Item -Recurse -Force bin }" + $(PWSH) "if (Test-Path bin) { Remove-Item -Recurse -Force bin }" # Help target help: - $(PWSH) "Write-Host 'Windows Makefile for git-sizer' -ForegroundColor Cyan" - $(PWSH) "Write-Host ''" - $(PWSH) "Write-Host 'Targets:' -ForegroundColor Green" - $(PWSH) "Write-Host ' all - Build git-sizer (default)'" - $(PWSH) "Write-Host ' test - Run tests'" - $(PWSH) "Write-Host ' clean - Clean build artifacts'" - $(PWSH) "Write-Host ''" - $(PWSH) "Write-Host 'Example usage:' -ForegroundColor Green" - $(PWSH) "Write-Host ' nmake -f Makefile.win'" - $(PWSH) "Write-Host ' nmake -f Makefile.win test'" + $(PWSH) "Write-Host 'Windows Makefile for git-sizer' -ForegroundColor Cyan" + $(PWSH) "Write-Host ''" + $(PWSH) "Write-Host 'Targets:' -ForegroundColor Green" + $(PWSH) "Write-Host ' all - Build git-sizer (default)'" + $(PWSH) "Write-Host ' test - Run tests'" + $(PWSH) "Write-Host ' clean - Clean build artifacts'" + $(PWSH) "Write-Host ''" + $(PWSH) "Write-Host 'Example usage:' -ForegroundColor Green" + $(PWSH) "Write-Host ' make -f Makefile.win'" + $(PWSH) "Write-Host ' make -f Makefile.win test'" diff --git a/script/ensure-go-installed.ps1 b/script/ensure-go-installed.ps1 index 5479eec..3d653c1 100644 --- a/script/ensure-go-installed.ps1 +++ b/script/ensure-go-installed.ps1 @@ -1,7 +1,7 @@ # This script is meant to be sourced with ROOTDIR set. if (-not $env:ROOTDIR) { - Write-Error 'ensure-go-installed.ps1 invoked without ROOTDIR set!' + $env:ROOTDIR = (Resolve-Path (Join-Path $scriptDir "..")).Path } # Function to check if Go is installed and at least version 1.21