Skip to content

Conversation

@dan-hughes
Copy link
Contributor

@dan-hughes dan-hughes commented Nov 17, 2025

Pull Request (PR) description

Only run the other git commands if git add was successful.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the file CHANGELOG.md.
    Entry should say what was changed and how that affects users (if applicable), and
    reference the issue being resolved (if applicable).
  • Documentation added/updated in README.md.
  • Comment-based help added/updated.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

@coderabbitai
Copy link

coderabbitai bot commented Nov 17, 2025

Walkthrough

The changes add validation to the Publish-WikiContent script to verify that the git add command succeeds before proceeding with subsequent git operations (commit, tag, push). If git add fails, the script logs an error and skips the remaining operations rather than continuing and failing downstream. A new localized error message supports this validation, and CHANGELOG.md documents the fix.

Changes

Cohort / File(s) Summary
Git Add Validation
source/Public/Publish-WikiContent.ps1
Introduces a guard that captures the exit code of the git add operation. Subsequent operations (commit, tag, push, completion messaging) are now nested and only execute if add succeeds (ExitCode not equal to 1). On failure, logs a GitAddFailedMessage and halts the workflow.
Error Message Support
source/en-US/DscResource.DocGenerator.strings.psd1
Adds new string entry GitAddFailedMessage with value "Adding Git changes failed, Wiki will not be updated."
Documentation
CHANGELOG.md
Documents the fix in a new Fixed subsection under Unreleased, referencing issue #172.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • source/Public/Publish-WikiContent.ps1: Verify that the exit code check correctly identifies git add failures and that the nested control flow ensures commit/tag/push operations are safely skipped on failure.
  • source/en-US/DscResource.DocGenerator.strings.psd1: Confirm the error message string is properly referenced in the PowerShell script.

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses issue #172 by adding a guard for git add failure, preventing commit/push when add fails, but does not fully resolve the original issue about 'nothing to commit' scenarios. Add a check to detect when there are no staged changes after git add succeeds, and skip commit/push operations in that case to fully resolve issue #172.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a check for successful git command execution in Publish-WikiContent.
Description check ✅ Passed The description is related to the changeset, explaining the fix ensures subsequent git commands run only if git add succeeds, and references issue #172.
Out of Scope Changes check ✅ Passed All changes are in scope: updating Publish-WikiContent.ps1 with git add validation, adding localization string GitAddFailedMessage, and updating CHANGELOG.md as required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dan-hughes
Copy link
Contributor Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
CHANGELOG.md (1)

16-20: Unreleased changelog entry is correct; optional tweak to issue link text

The new ### Fixed entry under [Unreleased] is well‑placed, concise, and correctly references #172; it also respects the “Keep a Changelog” and “≤2 items per change type” guidance.
If you want to align more strictly with the documented style, you could change the link text to issue #172 to match the recommended [issue #<number>] format, but this is purely cosmetic given existing entries.

Based on learnings

source/en-US/DscResource.DocGenerator.strings.psd1 (1)

3-29: New localized GitAddFailedMessage looks good

The GitAddFailedMessage entry is correctly localized and matches surrounding formatting and naming conventions in this file. No functional issues.

If you later adopt the (PREFIX####) ID pattern in this module, this would be a good candidate to update at the same time, but it’s not blocking.

Based on learnings

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 985f3e9 and 727d4af.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • source/Public/Publish-WikiContent.ps1 (1 hunks)
  • source/en-US/DscResource.DocGenerator.strings.psd1 (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow Requirements

  • Run PowerShell script files from repository root
  • Setup build and test environment (once per pwsh session): ./build.ps1 -Tasks noop
  • Build project before running tests: ./build.ps1 -Tasks build
  • Always run tests in new pwsh session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • CHANGELOG.md
  • source/en-US/DscResource.DocGenerator.strings.psd1
  • source/Public/Publish-WikiContent.ps1
**/*.md

⚙️ CodeRabbit configuration file

**/*.md: # Markdown Style Guidelines

  • Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
  • Use 2 spaces for indentation
  • Use '1.' for all items in ordered lists (1/1/1 numbering style)
  • Disable MD013 rule by adding a comment for tables/code blocks exceeding 80 characters
  • Empty lines required before/after code blocks and headings (except before line 1)
  • Escape backslashes in file paths only (not in code blocks)
  • Code blocks must specify language identifiers

Text Formatting

  • Parameters: bold
  • Values/literals: inline code
  • Resource/module/product names: italic
  • Commands/files/paths: inline code

Files:

  • CHANGELOG.md
CHANGELOG.md

⚙️ CodeRabbit configuration file

CHANGELOG.md: # Changelog Guidelines

  • Always update the Unreleased section in CHANGELOG.md
  • Use Keep a Changelog format
  • Describe notable changes briefly, ≤2 items per change type
  • Reference issues using format issue #<issue_number>
  • No empty lines between list items in same section
  • Skip adding entry if same change already exists in Unreleased section
  • No duplicate sections or items in Unreleased section

Files:

  • CHANGELOG.md
{**/*.ps1,**/*.psm1,**/*.psd1}

⚙️ CodeRabbit configuration file

{**/*.ps1,**/*.psm1,**/*.psd1}: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description...

Files:

  • source/en-US/DscResource.DocGenerator.strings.psd1
  • source/Public/Publish-WikiContent.ps1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Publish-WikiContent.ps1
🧠 Learnings (10)
📚 Learning: 2025-09-16T16:35:31.909Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-09-16T16:35:31.909Z
Learning: Applies to CHANGELOG.md : Always update the Unreleased section of CHANGELOG.md

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-09-14T19:17:05.477Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-changelog.instructions.md:0-0
Timestamp: 2025-09-14T19:17:05.477Z
Learning: Applies to CHANGELOG.md : Always update the Unreleased section in CHANGELOG.md

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-09-14T19:17:05.477Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-changelog.instructions.md:0-0
Timestamp: 2025-09-14T19:17:05.477Z
Learning: Applies to CHANGELOG.md : Describe notable changes briefly, with no more than 2 items per change type

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-09-14T19:17:05.477Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-changelog.instructions.md:0-0
Timestamp: 2025-09-14T19:17:05.477Z
Learning: Applies to CHANGELOG.md : No duplicate sections or items in the Unreleased section

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-09-14T19:17:05.477Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-changelog.instructions.md:0-0
Timestamp: 2025-09-14T19:17:05.477Z
Learning: Applies to CHANGELOG.md : Skip adding an entry if the same change already exists in the Unreleased section

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-09-14T19:17:05.477Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-changelog.instructions.md:0-0
Timestamp: 2025-09-14T19:17:05.477Z
Learning: Applies to CHANGELOG.md : Use Keep a Changelog format

Applied to files:

  • CHANGELOG.md
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/en-US/*.strings.psd1 : Define strings using ConvertFrom-StringData with entries like `KeyName = Message with {0} placeholder. (PREFIX0001)`

Applied to files:

  • source/en-US/DscResource.DocGenerator.strings.psd1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use localized strings for all messages (e.g., Write-Verbose, Write-Error)

Applied to files:

  • source/en-US/DscResource.DocGenerator.strings.psd1
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : Use localized string keys instead of hardcoded strings in script output/messages

Applied to files:

  • source/en-US/DscResource.DocGenerator.strings.psd1
📚 Learning: 2025-09-12T13:20:57.155Z
Learnt from: CR
Repo: dsccommunity/SqlServerDsc PR: 0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-09-12T13:20:57.155Z
Learning: Applies to source/DSCResources/**/*.psm1 : Import localized strings at the top of the module using Get-LocalizedData

Applied to files:

  • source/en-US/DscResource.DocGenerator.strings.psd1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test Publish Code Coverage)
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test Unit macOS)
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test Integration)
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test Unit Linux)
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test HQRM)
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test Unit Windows (WPS))
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Test Unit Windows (PS))
  • GitHub Check: dsccommunity.DscResource.DocGenerator (Build Package Module)

Comment on lines 167 to +192
Write-Verbose -Message $script:localizedData.AddWikiContentToGitRepoMessage

Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' )
$gitAddResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' ) -PassThru

Write-Verbose -Message ($script:localizedData.CommitAndTagRepoChangesMessage -f $ModuleVersion)
if ($gitAddResult.ExitCode -eq 1)
{
Write-Verbose -Message $script:localizedData.GitAddFailedMessage
}
else
{
Write-Verbose -Message ($script:localizedData.CommitAndTagRepoChangesMessage -f $ModuleVersion)

Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'commit', '--message', "`"$($script:localizedData.UpdateWikiCommitMessage -f $ModuleVersion)`"" )
Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'commit', '--message', "`"$($script:localizedData.UpdateWikiCommitMessage -f $ModuleVersion)`"" )

Write-Verbose -Message $script:localizedData.PushUpdatedRepoMessage
Write-Verbose -Message $script:localizedData.PushUpdatedRepoMessage

Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'tag', '--annotate', $ModuleVersion, '--message', $ModuleVersion )
Invoke-Git -WorkingDirectory $tempPath `
-Arguments @( 'tag', '--annotate', $ModuleVersion, '--message', $ModuleVersion )

Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin' )
Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin' )

Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin', $ModuleVersion )
Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin', $ModuleVersion )

Write-Verbose -Message $script:localizedData.PublishWikiContentCompleteMessage
Write-Verbose -Message $script:localizedData.PublishWikiContentCompleteMessage
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

Git add guard has correctness gaps and doesn’t yet fix the “nothing to commit” failure from issue #172

A few points on this new block:

  1. Exit code check is too narrow

    if ($gitAddResult.ExitCode -eq 1)
    {
        Write-Verbose -Message $script:localizedData.GitAddFailedMessage
    }
    else
    {
        # commit / tag / push
    }
    • Any non‑zero exit code other than 1 will be treated as “success” and still run commit/tag/push, even though git add actually failed.
    • You almost certainly want to treat any non‑zero exit code as failure:
    if ($gitAddResult.ExitCode -ne 0)
    {
        # handle failure
    }
  2. Real git‑add failures are silently downgraded to verbose

    • In the failure branch you only emit Write-Verbose. With default settings this is invisible, while the comment/message says “Wiki will not be updated”.
    • For an actual git error, callers likely expect the command to clearly fail (e.g., via Write-Error or a terminating error), not just silently skip the publish.
  3. Issue Publishing Wiki content fails if there’s nothing to commit #172 (“nothing to commit, working tree clean”) is not addressed

    • The reported problem is that git commit returns a non‑zero exit code when there’s nothing to commit, causing Publish-WikiContent to fail.
    • git add * still exits 0 when there are no changes, so this guard does not prevent the git commit invocation from running in that scenario.
    • Invoke-Git is still called for commit without -PassThru, so if git commit returns 1 with “nothing to commit, working tree clean”, it will still throw and fail the build as before.

    To truly fix Publishing Wiki content fails if there’s nothing to commit #172 you need to short‑circuit before commit/tag/push when there are no staged changes, for example by using git status --porcelain with -PassThru and the existing NothingToCommitToWiki localized message.

  4. Suggested direction

    Consider something along these lines:

    -        $gitAddResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' ) -PassThru
    -
    -        if ($gitAddResult.ExitCode -eq 1)
    -        {
    -            Write-Verbose -Message $script:localizedData.GitAddFailedMessage
    -        }
    -        else
    -        {
    +        $gitAddResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'add', '*' ) -PassThru
    +
    +        if ($gitAddResult.ExitCode -ne 0)
    +        {
    +            Write-Error -Message $script:localizedData.GitAddFailedMessage `
    +                -Category InvalidOperation `
    +                -ErrorId 'PublishWikiContent_GitAddFailed' `
    +                -TargetObject $tempPath
    +
    +            return
    +        }
    +
    +        # No staged changes => nothing to commit; exit gracefully.
    +        $gitStatusResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'status', '--porcelain' ) -PassThru
    +
    +        if ([string]::IsNullOrWhiteSpace($gitStatusResult.StandardOutput))
    +        {
    +            Write-Verbose -Message $script:localizedData.NothingToCommitToWiki
    +            return
    +        }
    +
    +        {
                Write-Verbose -Message ($script:localizedData.CommitAndTagRepoChangesMessage -f $ModuleVersion)
                Invoke-Git -WorkingDirectory $tempPath `
                    -Arguments @( 'commit', '--message', "`"$($script:localizedData.UpdateWikiCommitMessage -f $ModuleVersion)`"" )
                Write-Verbose -Message $script:localizedData.PushUpdatedRepoMessage
                Invoke-Git -WorkingDirectory $tempPath `
                    -Arguments @( 'tag', '--annotate', $ModuleVersion, '--message', $ModuleVersion )
                Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin' )
                Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'push', 'origin', $ModuleVersion )
                Write-Verbose -Message $script:localizedData.PublishWikiContentCompleteMessage
            }

    This way:

Please re‑run the scenario from issue #172 (no changes in the wiki repo) with this function to confirm that Publish-WikiContent no longer fails when there is nothing to commit, and that genuine git errors are still visible to callers.


I'll help you verify this review comment. Let me gather the necessary information by examining the codebase.

Now let me examine the actual codebase:

Now let me examine the actual file and verify the code exists:


🏁 Script executed:

#!/bin/bash
# Check if file exists and examine lines 167-192
if [ -f "source/Public/Publish-WikiContent.ps1" ]; then
    echo "=== Lines 167-192 from Publish-WikiContent.ps1 ==="
    sed -n '167,192p' "source/Public/Publish-WikiContent.ps1"
else
    echo "File not found: source/Public/Publish-WikiContent.ps1"
    find . -name "Publish-WikiContent.ps1" -type f 2>/dev/null | head -5
fi

Length of output: 1233


🏁 Script executed:

#!/bin/bash
# Find and examine Invoke-Git implementation
echo "=== Searching for Invoke-Git function definition ==="
rg -nA 30 'function Invoke-Git' --type ps1 -B 2 | head -80

Length of output: 80


🏁 Script executed:

#!/bin/bash
# Check for localized string key definitions
echo "=== Searching for localized string keys ==="
rg -nA 2 'GitAddFailedMessage|NothingToCommitToWiki' --type psd1 | head -40

Length of output: 72


Let me continue verification with corrected search commands:

Now let me search for the Invoke-Git function and localized strings in the codebase:


🏁 Script executed:

#!/bin/bash
# Find Invoke-Git function without type filter
echo "=== Searching for Invoke-Git function definition ==="
rg -nA 15 'function Invoke-Git' --context=3 | head -100

Length of output: 477


🏁 Script executed:

#!/bin/bash
# Check for localized string key definitions (no type filter)
echo "=== Searching for localized string keys ==="
rg -n 'GitAddFailedMessage|NothingToCommitToWiki' --context=2 | head -60

Length of output: 2729


🏁 Script executed:

#!/bin/bash
# Look for strings.psd1 files to understand where keys are defined
echo "=== Locating strings.psd1 files ==="
find . -name "*.strings.psd1" -type f 2>/dev/null | head -20

Length of output: 88


Now let me examine the Invoke-Git implementation more closely to understand -PassThru behavior:


🏁 Script executed:

#!/bin/bash
# Get full Invoke-Git function implementation
echo "=== Full Invoke-Git function ==="
sed -n '32,120p' source/Public/Invoke-Git.ps1

Length of output: 2981


🏁 Script executed:

#!/bin/bash
# Check Out-GitResult to understand error handling
echo "=== Out-GitResult function start ==="
sed -n '1,100p' source/Private/Out-GitResult.ps1

Length of output: 2778


🏁 Script executed:

#!/bin/bash
# Check how commit/tag/push are called (without -PassThru)
echo "=== Checking Invoke-Git calls in Publish-WikiContent ==="
rg -n 'Invoke-Git' source/Public/Publish-WikiContent.ps1 -B1 -A1 | head -60

Length of output: 1537


Exit code check is too narrow and doesn't prevent the "nothing to commit" failure from issue #172

The new code introduces several issues:

  1. Exit code check only catches 1, not all failures

    The condition if ($gitAddResult.ExitCode -eq 1) catches only exit code 1, but any other non-zero exit code from git add is silently treated as success and continues to the commit/tag/push block. This should be:

    if ($gitAddResult.ExitCode -ne 0)
  2. Real git-add errors are only logged verbosely

    When git add fails with exit code 1, only Write-Verbose is called. Since verbose output is disabled by default, actual git errors are invisible to callers. Error-level output should be used to surface real failures.

  3. The "nothing to commit" failure (Publishing Wiki content fails if there’s nothing to commit #172) is not prevented

    The core issue remains unsolved: git add * exits with code 0 even when there are no changes, so this guard doesn't short-circuit before git commit. When git commit runs and finds nothing to commit, it exits with code 1. Since commit is called without -PassThru, Invoke-Git throws, causing the function to fail—the exact Publishing Wiki content fails if there’s nothing to commit #172 problem.

    To fix this, detect when there are no staged changes before attempting commit. Use git status --porcelain with -PassThru and short-circuit gracefully:

    $gitStatusResult = Invoke-Git -WorkingDirectory $tempPath -Arguments @( 'status', '--porcelain' ) -PassThru
    
    if ([string]::IsNullOrWhiteSpace($gitStatusResult.StandardOutput))
    {
        Write-Verbose -Message $script:localizedData.NothingToCommitToWiki
        return
    }
🤖 Prompt for AI Agents
In source/Public/Publish-WikiContent.ps1 around lines 167-192, the git-add
handling is too narrow and doesn't prevent the "nothing to commit" failure:
change the exit-code check to treat any non-zero as failure (use -ne 0) and log
real git-add failures with an error-level call rather than Write-Verbose; after
git add run git status --porcelain with -PassThru and if its StandardOutput is
empty write the localized "NothingToCommitToWiki" message and return early to
avoid running commit/tag/push; also invoke commit (and other critical git
commands) with -PassThru and verify their ExitCode so failures are handled
explicitly rather than letting Invoke-Git throw unobserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publishing Wiki content fails if there’s nothing to commit

1 participant