Repository navigation
fix(cp): refuse to run with staged changes or an edited source file - #1300
Open
jayhemnani9910 wants to merge 2 commits into
Open
jayhemnani9910 wants to merge 2 commits into
jayhemnani9910 wants to merge 2 commits into
Conversation
spacewander
reviewed
Dec 4, 2026
|
|
||
| # The copy is made with commits, which would take in anything staged | ||
| # and any unsaved edit of the source file. | ||
| if ! git diff --cached --quiet || ! git diff --quiet -- "$CURRENT_FILENAME"; then |
Collaborator
There was a problem hiding this comment.
git diff --quiet -- "$CURRENT_FILENAME" treat name as pathspec, not literal. Try git diff --quiet -- ":(literal)$CURRENT_FILENAME"?
Contributor
Author
There was a problem hiding this comment.
Done in 8502310, with a test that copies a file named fil? while file has edits.
| echo 1>&2 "You have staged changes or changes to $CURRENT_FILENAME." | ||
| echo 1>&2 "Commit or stash them first." | ||
| exit 50 | ||
| fi |
Collaborator
There was a problem hiding this comment.
Better to guard run after destination check
Contributor
Author
There was a problem hiding this comment.
Moved it after the */ destination check in 8502310, so it runs before any directory is created.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
git cpmakes the copy with two commits on a temporary branch, and those commits take the whole index. Anything already staged ends up in the copy commits and is merged into the current branch:If the source file has unsaved edits, the edit is moved into the copy and
git checkout -then stops ("Please commit your changes or stash them"). The repo is left ongit-cp-<timestamp>, and the source is back to its committed text.git cpnow stops before doing anything if something is staged or the source file has changes. Unstaged changes to other files are not touched and still work as before.Testing: added
tests/git-cp.bats. The two refusal tests fail on master and pass with this change, and the full bats suite passes.AI tools assisted with this contribution.