Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean working directory skip paths #11102

Merged

Conversation

scottsumrall
Copy link
Contributor

Fixes #11099

Proposed changes

  • Allow users to exclude certain file paths when cleaning repository

Screenshots

Before

image

After

image

Test methodology

  • Manually tested in local repository
  • Added and ran relevant unit tests for new functionality

Test environment(s)

  • GIT 2.41.0 windows.2
  • Windows 10

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned scottsumrall Jul 13, 2023
GitExtensions.sln Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.Designer.cs Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.Designer.cs Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.cs Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.cs Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.cs Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.cs Outdated Show resolved Hide resolved
GitUI/CommandsDialogs/FormCleanupRepository.resx Outdated Show resolved Hide resolved
GitUI/GitExtensionsForm.resx Outdated Show resolved Hide resolved
@ghost ghost added 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity and removed 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity labels Jul 14, 2023
@scottsumrall scottsumrall marked this pull request as draft July 14, 2023 19:36
@scottsumrall scottsumrall marked this pull request as ready for review July 18, 2023 19:17
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

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

looks OK, no deep review, not run

GitUI/CommandsDialogs/FormCleanupRepository.Designer.cs Outdated Show resolved Hide resolved
@RussKie RussKie added 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity and removed 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity labels Jul 30, 2023
Copy link
Member

@pmiossec pmiossec left a comment

Choose a reason for hiding this comment

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

Please use the more meaningful --exclude option string

// 3. Replace whitespace with '?' and convert to POSIX path
// 3. join together with space as separator

return string.Join(" ", textBoxExcludePaths.Lines.Where(a => !string.IsNullOrEmpty(a)).Select(a => string.Format("-e {0}", a.Replace(" ", "?")).ToPosixPath()));
Copy link
Member

Choose a reason for hiding this comment

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

Please use the more meaningful --exclude (short option format should be used only by humans when typing the command from command line)

I also would have preferred a better letter than 'a'. 'p' for 'path'?

And maybe use string interpolation instead of string.Format()?

{
return null;
}

// 1. get all lines from text box which are not empty
// 2. wrap lines with ""
// 3. join together with space as separator
return string.Join(" ", textBoxPaths.Lines.Where(a => !string.IsNullOrEmpty(a)).Select(a => string.Format("\"{0}\"", a)));
return string.Join(" ", textBoxIncludePaths.Lines.Where(a => !string.IsNullOrEmpty(a)).Select(a => string.Format("\"{0}\"", a)));
Copy link
Member

Choose a reason for hiding this comment

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

I would have preferred a better letter than 'a'. 'p' for 'path'?

And maybe use string interpolation instead of string.Format()?

Should we convert to posix path here also?

@ghost ghost added 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity and removed 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity labels Jul 30, 2023
@mstv
Copy link
Member

mstv commented Aug 2, 2023

Could you rebase and resolve the conflicts, please?

Conflicting files

  • GitUI/CommandsDialogs/FormCleanupRepository.Designer.cs
  • GitUI/CommandsDialogs/FormCleanupRepository.cs
  • contributors.txt

@scottsumrall scottsumrall reopened this Aug 3, 2023
}

// 1. get all lines from text box which are not empty
// 2. Prepend lines with '-e '
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// 2. Prepend lines with '-e '
// 2. Prepend lines with '--exclude '

Same for tests -e there too.

I also would prefer to move this to GitCommandHelpers.cs, just providing the string or an array (if checkbox set).
(This would affect tests too.)
But I leave this to another maintainer to request, I can live with this.

@RussKie
Copy link
Member

RussKie commented Aug 6, 2023

Judging by the number of commits it doesn't look like you managed to cleanly rebase your work. E.g., there are unrelated commits:
image

Please perform a clean rebase of your work on top of the latest master. https://github.com/gitextensions/gitextensions/wiki/How-To%3A-Squash-and-Rebase-your-changes#rebase may be of some help.

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

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

Please rebase

@ghost ghost added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Aug 6, 2023
@scottsumrall
Copy link
Contributor Author

Judging by the number of commits it doesn't look like you managed to cleanly rebase your work. E.g., there are unrelated commits: image

Please perform a clean rebase of your work on top of the latest master. https://github.com/gitextensions/gitextensions/wiki/How-To%3A-Squash-and-Rebase-your-changes#rebase may be of some help.

Apologies for the mix up, still figuring out the git workflow. Please let me know if this is looking correct.
image
Additionally, are you saying I should squash these commits together?

@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Aug 7, 2023
@gerhardol
Copy link
Member

It is not fixed. Rebase preserving commits is not straight forward as there are intermediate conflicts.

In this case, it is easiest to squash on the BASE (soft reset), commit with proper message and then rebase on master. There are quite some commits here, I do not think they add value in a further review (review has basically to be restarted, in this case it is OK).
There should only be 6 changed files in the commit, other files have not been changed in master.

@scottsumrall
Copy link
Contributor Author

It is not fixed. Rebase preserving commits is not straight forward as there are intermediate conflicts.

In this case, it is easiest to squash on the BASE (soft reset), commit with proper message and then rebase on master. There are quite some commits here, I do not think they add value in a further review (review has basically to be restarted, in this case it is OK). There should only be 6 changed files in the commit, other files have not been changed in master.

Would you mind taking a look at this temp branch I made? I'd like to make sure I'm doing this right before I start overwriting things here.
master...scottsumrall:gitextensions:skip-paths-test

To get this PR's branch to the same state I should just need to force push then do a simple rebase for the latest changes.

@gerhardol
Copy link
Member

Would you mind taking a look at this temp branch I made? I'd like to make sure I'm doing this right before I start overwriting things here. master...scottsumrall:gitextensions:skip-paths-test

Fine, except that GitCommandHelpersTest.cs still has -e instead of --exclude
Hope you learn something!

@scottsumrall scottsumrall force-pushed the clean-working-directory-skip-paths branch from 3a9c2a8 to c18c621 Compare August 12, 2023 02:08
@scottsumrall scottsumrall force-pushed the clean-working-directory-skip-paths branch from c18c621 to 172e5fd Compare August 12, 2023 02:09
@scottsumrall
Copy link
Contributor Author

Appreciate the assistance!

@RussKie
Copy link
Member

RussKie commented Aug 12, 2023

@scottsumrall thank you.

@gerhardol please merge, if all your feedback is addressed.

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

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

LGTM, have not run

string cmdOutput = FormProcess.ReadDialog(this, arguments: cleanUpCmd, Module.WorkingDir, input: null, useDialogSettings: true);
PreviewOutput.Text = EnvUtils.ReplaceLinuxNewLinesDependingOnPlatform(cmdOutput);

if (CleanSubmodules.Checked)
{
var cleanSubmodulesCmd = GitCommandHelpers.CleanSubmodules(mode, dryRun: true, directories: RemoveDirectories.Checked, paths: pathArgument);
var cleanSubmodulesCmd = GitCommandHelpers.CleanSubmodules(mode, dryRun: true, directories: RemoveDirectories.Checked, paths: includePathArgument);
Copy link
Member

Choose a reason for hiding this comment

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

❔ Should we apply excludePathArguments for submodules, too?

Copy link
Member

Choose a reason for hiding this comment

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

I see two viewpoints:

  • Paths are relative the superproject and only should be relative the master. Hard to implement though, if wildcards are to be allowed.
  • apply the same as for the superproject, similar to include paths. Easier to implement, maybe not expected?

Probably second option.
@scottsumrall thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I completely follow. As of right now, the excludes for the general clean are only for excluding individual files and do not support wildcards. I assume it would be the same for submodules? If we want this feature included I would lean towards the first solution but the second option seems fine for its current state.

Copy link
Member

Choose a reason for hiding this comment

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

The first option would affect the include files too. But that wasrecently added without consideration.
However, I do not find it reasonable.
Use second alternative, in this PR before merge.

Add exclude paths to CleanSubmodules()
(Make sure there is a test as well, also for include not tested at all now)

GitUI/CommandsDialogs/FormCleanupRepository.cs Outdated Show resolved Hide resolved
@gerhardol
Copy link
Member

I pushed some commits, the merge was bad and preview removed files.
Part of that was that use of common code I suggsested in #11101 was not done, so I added it again.
Also using string interpolation instead of string.format - pushed a change instead of suggesting (also for existing code)

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Aug 13, 2023
@gerhardol
Copy link
Member

@scottsumrall Please acknowledge the changes and I will merge

@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Aug 13, 2023
@scottsumrall
Copy link
Contributor Author

Looks good to me

@RussKie RussKie merged commit b94bd9c into gitextensions:master Aug 14, 2023
3 of 4 checks passed
@ghost ghost added this to the vNext milestone Aug 14, 2023
@scottsumrall
Copy link
Contributor Author

@gerhardol Should I just open a new PR with the changes we discussed or should I create a new issue?

@gerhardol
Copy link
Member

@gerhardol Should I just open a new PR with the changes we discussed or should I create a new issue?

A new PR only is enough. PR not needed regardless - not big enough to track in my opinion, still reasonable to make this change 'complete'.

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.

Let skip paths in cleaning working directory feature
5 participants