-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow skipping file paths in recursive submodule directory clean #11163
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using GitCommands; | ||
using System.Collections.Generic; | ||
using GitCommands; | ||
using GitCommands.Git.Commands; | ||
using GitCommands.Utils; | ||
using GitExtUtils; | ||
|
@@ -63,7 +64,7 @@ private void CleanUp(bool dryRun) | |
|
||
if (CleanSubmodules.Checked) | ||
{ | ||
ArgumentString cleanSubmodulesCmd = GitCommandHelpers.CleanSubmodules(mode, dryRun, directories: RemoveDirectories.Checked, paths: includePathArgument); | ||
ArgumentString cleanSubmodulesCmd = GitCommandHelpers.CleanSubmodules(mode, dryRun, directories: RemoveDirectories.Checked, paths: includePathArgument, excludes: excludePathArguments); | ||
cmdOutput = FormProcess.ReadDialog(this, arguments: cleanSubmodulesCmd, Module.WorkingDir, input: null, useDialogSettings: true); | ||
PreviewOutput.Text += EnvUtils.ReplaceLinuxNewLinesDependingOnPlatform(cmdOutput); | ||
} | ||
|
@@ -164,11 +165,29 @@ private void AddExcludePath_Click(object sender, EventArgs e) | |
|
||
if (path is not null) | ||
{ | ||
path = path.Replace(Module.WorkingDir, ""); | ||
path = MakePathRelativeToModule(path); | ||
textBoxExcludePaths.Text += path; | ||
} | ||
} | ||
|
||
private string MakePathRelativeToModule(string targetPath) | ||
{ | ||
targetPath = targetPath.Replace(Module.WorkingDir, "").ToPosixPath(); | ||
IReadOnlyList<string> submodulePaths = Module.GetSubmodulesLocalPaths(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I was not clear, but it may be clearer to not resolve a relative path here. Regex cannot be resolved anyway. If replaced, the exclude (and include) path should be changed for each submodule individually. The "cleaned" path could be have an unexpected effect for the other superprojects and submodules. There may be layers of submodules too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, I uploaded this as draft to get clarification but forgot to comment. From my understanding, I don't see a clear way to avoid weird edge case conflicts without changes to #11101. The exclude parameter requires that the path be relative to the submodule. For example if the user wants to exclude: Since I don't think the include has a similar requirement, I don't necessarily think it needs to be changed for each submodule individually? I believe this is due to the exclude parameter following gitignore rules while the pathspec parameter (includes) just uses general file paths. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe no manipulation is easier to explain, so that is my preference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either I didn't explain myself well or I am misunderstanding, apologies. By no manipulation do you mean using the full path? I am saying that, from my understanding, the --exclude parameter fundamentally requires that the path be written relative to module, as in my previous example. This is because we aren't passing in a path, we are passing in a Glob pattern since the --exclude parameter follows gitignore rules. As we iterate through each submodule, the exclude pattern gets applied relative to the submodule the clean command is being run within. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(missed this, sorry) The exclude can be a regex, then the path cannot be resolved. The paths that applies to the superproject will apply to the submodules anyway. There is also a question on how sub-submodules should be handled. It is just easier to explain if exactly the same set is applied to all clean commands. Regardless, the handling should be the same for include/exclude. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In git command line, the behavior is not exactly the same as @scottsumrall said. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gets a little messy since the code was designed using the GUI to store the file paths. I think it might be better to separate the code from the UI. Then I could just put whatever path we want displayed in the GUI and store the proper, transformed path in code. This would also get rid of some unnecessary parsing steps. It's a bit out of scope for this PR but I think it would be beneficial. In terms of what we want to display, this would give a lot of flexibility. Since the excludes need to be relative to the module just appending the parent module might be clear enough. This would be closest to matching the command line output while still having some level of clarity for the user. E.g.
could look like
could look like
Its important to note though that this is only a surface level change and the edge cases of matching files of the same relative path in different submodules will still be an issue. I am unsure how to address this other than modifying #11101 to iterate through submodules in code rather than via command line. This would allow me to only apply the relevant exclude patterns for each module. |
||
|
||
string? nearestSubmodule = submodulePaths | ||
.Where(submodulePath => targetPath.StartsWith(submodulePath)) | ||
.OrderByDescending(submodulePath => submodulePath.Length) | ||
.FirstOrDefault(); | ||
|
||
if (nearestSubmodule is null) | ||
{ | ||
return targetPath; | ||
} | ||
|
||
return targetPath[(nearestSubmodule.Length + 1)..]; | ||
} | ||
|
||
private string? RequestUserFolderPath() | ||
{ | ||
using FolderBrowserDialog dialog = new() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔
This should be tested, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested, this doesn't work since WorkingDir is not stored as Posix path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the user need to input paths in the native form in order to match WorkingDir?
I would not make assumptions on the type of path separators in WorkingDir either.
I.e. convert both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.