Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 13, 2025

The scripts/test.sh git hook script was unconditionally popping the stash even when no stash was created, which could affect unrelated stashes or cause errors.

The issue occurred because:

  • git stash push --keep-index only creates a stash when there are unstaged changes
  • When no unstaged changes exist, the command outputs "No local changes to save" but succeeds
  • The script would then unconditionally run git stash pop, potentially popping an unrelated stash

This fix captures the output of git stash push and only runs git stash pop when a stash was actually created (indicated by "Saved working directory" in the output).

Before:

run_cmd "git stash push --keep-index --message precommit"
# ... build steps ...
run_cmd "git stash pop"  # Always runs, even if no stash was created

After:

stash_output=$(git stash push --keep-index --message precommit 2>&1)
# ... check if stash was created ...
if [[ "${stash_created}" == true ]]; then
    run_cmd "git stash pop"  # Only runs when needed
fi

The fix maintains the same output formatting and user experience while making the script more robust.

Fixes #3225.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.sheetjs.com
    • Triggering command: node /usr/local/bin/yarn install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Capture git stash push output to detect if stash was created
- Only run git stash pop if a stash was actually created
- Prevents popping unrelated stashes when no changes exist
- Maintains same output formatting and user experience

Co-authored-by: RichDom2185 <[email protected]>
@Copilot Copilot AI changed the title [WIP] Custom git hook script should only conditionally pop stash Fix conditional stash pop in git hook script Aug 13, 2025
@Copilot Copilot AI requested a review from RichDom2185 August 13, 2025 11:01
Copilot finished work on behalf of RichDom2185 August 13, 2025 11:01
@RichDom2185 RichDom2185 requested a review from heyzec August 13, 2025 11:12
@RichDom2185 RichDom2185 marked this pull request as ready for review August 13, 2025 11:55
@coveralls
Copy link

Pull Request Test Coverage Report for Build 16936442223

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 43.454%

Totals Coverage Status
Change from base Build 16931123815: 0.0%
Covered Lines: 20627
Relevant Lines: 49674

💛 - Coveralls

@heyzec
Copy link
Contributor

heyzec commented Aug 13, 2025

@heyzec
Copy link
Contributor

heyzec commented Aug 13, 2025

I tested this and it works. Nits:

(1) Output when testing with git hook run pre-push

> git stash push --keep-index --message precommit
  Saved working directory and index state On copilot/fix-3225: precommit
  If you cancel this pre-push hook, use `git stash pop` to retrieve your
  unstaged changes.

Ideally I'd prefer if Saved working directory and index state On copilot/fix-3225: precommit message is hidden (the output of this git command was not shown before this PR)

(2) Script

    stash_output=$(git stash push --keep-index --message precommit 2>&1)
    echo_cyan "> git stash push --keep-index --message precommit"

Would be nice if it was not duplicated

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.

Custom git hook script should only conditionally pop stash
4 participants