Windows is able to handle case-sensitive files by using this command on folders:
fsutil.exe file setCaseSensitiveInfo "C:\examplefolderpath" enable
However, the issue with this is that it doesn't automatically apply to subfolders... There is a way to apply it to subfolders using PowerShell, but they have to actually exist first. Thus, I'm looking for a way to retrieve a git repo's folder structure without actually downloading any of its files. Only after the folder structureis created and I've run the PowerShell command do I want to checkout the files.
Is there a convenient way to do this using git commands alone?
If not, is there a way for PowerShell to retrieve the folder structure from a bare git repository (using git clone --bare
) and setup the folder structure? (For a side-project I'm working on, it would also be useful to know how to do this using Go, unless git commands alone can do it. But, this isn't as important as knowing how to do it with PowerShell.)
CodePudding user response:
Git doesn't provide a way to check out only the directories and not the files. You have some options, though:
- Use Git in WSL to create the repository, which according to this article will mean that they'll automatically be made case sensitive.
- Avoid running
git checkout
and find the file hierarchy withgit ls-tree -rd HEAD
(or whatever revision you want instead ofHEAD
), then generate those directories, and only then rungit checkout
. However, note that PowerShell pipes are known to corrupt data passed through them, so this wouldn't be a good idea when working with Git.
If you want Git for Windows to support this natively, you could go over to their issue tracker and ask for this to supported natively as a feature. I don't know how much work it would be, and I'm unable to find documentation for the API required, so it's unclear whether it could be reasonably implemented in Git.
CodePudding user response:
With thanks to bk2204's answer for pointing me in the right direction... after creating a bare repo with ``, I can creature the directory structure with this function:
function Invoke-GitCloneCS {
[Alias('igccs')]
param([Parameter(Mandatory)] $url)
# Terminate function if user isn't admin
if (${env:=::}) { 'Function must be ran as administrator!'; return }
# Normalize URL so the variable ends in .git
$url = ("$url" -replace '.git$') -replace '$','.git'
# Derive repo name from $url
$repo = $url.Split('/')[-1] -replace '.git$'
git clone $url --no-checkout
# Navigate to repo directory and apply setCaseSensitiveInfo to it
Set-Location $repo -pv D | & { fsutil.exe file setCaseSensitiveInfo $D enable }
# Retrieve the folder structure
(git ls-tree --name-only -rd HEAD).ForEach({
# Create each folder listed, and apply setCaseSensitiveInfo to it
New-Item $_ -Type D -pv D | & { fsutil.exe file setCaseSensitiveInfo $D enable }})
git checkout
Set-Location ..
}
Now, that isn't the complete command, I still need to work in all the