Skip to content

issue-6910 clearer message with actionable hint for repo sync#7110

Merged
mislav merged 2 commits intocli:trunkfrom
macmacbr:issue-6910
Mar 28, 2023
Merged

issue-6910 clearer message with actionable hint for repo sync#7110
mislav merged 2 commits intocli:trunkfrom
macmacbr:issue-6910

Conversation

@macmacbr
Copy link
Contributor

@macmacbr macmacbr commented Mar 8, 2023

issue-6910 clearer message with actionable hint

Add hint to the gh repo sync error message for when there are untracked files.

Using git stash --all (or git stash --include-untracked) should help when people try to sync their local copy and
the --force option fails due to untracked files.

--
Fixes #6910

@macmacbr macmacbr requested a review from a team as a code owner March 8, 2023 17:11
@macmacbr macmacbr requested review from mislav and removed request for a team March 8, 2023 17:11
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Mar 8, 2023
@macmacbr macmacbr force-pushed the issue-6910 branch 2 times, most recently from 4f8629b to c10c679 Compare March 8, 2023 18:06
vilmibm
vilmibm previously requested changes Mar 8, 2023
Copy link
Contributor

@vilmibm vilmibm left a comment

Choose a reason for hiding this comment

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

Reading through the linked issue, it sounds like local changes was meant to be changed to untracked files also?

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thanks for working on making this better!

if currentBranch == branch {
if isDirty, err := git.IsDirty(); err == nil && isDirty {
return fmt.Errorf("can't sync because there are local changes; please stash them before trying again")
return fmt.Errorf("can't sync because there are local changes; please stash them before trying again. Use git stash --all for offending untracked files.")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of this error message since it can be potentially confusing to the user.

First, the IsDirty() method doesn't tell us what was "dirty" in the first place: was it a tracked file with uncommitted changes, an untracked file, or both? To answer that, we could in theory extend our git client with a more informative method based on UncommittedChangeCount, but that might require more work on this PR that you've bargained for, so for now let's maybe avoid that.

If an error message gives actionable instructions, we want those instructions to be as generic as possible and ideally work for everyone. The above error message essentially says to use stash or stash --all depending on the circumstances, but we have to keep in mind that the user doesn't necessarily understand the circumstances. The message should also ideally not be misleading, e.g. by suggesting that there might have been “offending untracked” files when there were none.

To address all that, I propose something like:

Suggested change
return fmt.Errorf("can't sync because there are local changes; please stash them before trying again. Use git stash --all for offending untracked files.")
return fmt.Errorf("refusing to sync due to uncommitted local changes.\nUse `git stash --all` before retrying sync and `git stash pop` afterwards")

In Go in general, this much sentence formatting in an error message is frowned upon, but since this error will be printed pretty much unchanged to stderr, multiline messages with sentences are fine when returned from the main command function itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That should help. I added some extra phrasing around it. Should make it clearer. Please let me know if you prefer the more compact phrasing.

@macmacbr macmacbr force-pushed the issue-6910 branch 2 times, most recently from 0e902f6 to 31110e7 Compare March 14, 2023 08:14
@samcoe samcoe requested review from mislav and vilmibm March 19, 2023 20:21
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Thanks! I've pushed a tweak to further simplify the error message.

@mislav mislav enabled auto-merge (squash) March 28, 2023 18:36
@mislav mislav merged commit 3b23978 into cli:trunk Mar 28, 2023
jtpetty pushed a commit that referenced this pull request May 22, 2023
Co-authored-by: Mislav Marohnić <mislav@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't sync repo with untracked files even after recommended stash

4 participants