Created
June 1, 2018 05:07
-
-
Save flaub/38b19b4e253a363da5677b33f0ceede5 to your computer and use it in GitHub Desktop.
git-big windows
This file contains 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
# experimental impl for core.symlinks = false | |
class WindowsFileSystem(FileSystem): | |
def islink(self, path, start=None): | |
if start: | |
path = os.path.relpath(path, start) | |
files = git('ls-files', '-s', path) | |
lines = files.splitlines() | |
if lines: | |
first_line = lines[0] | |
parts = first_line.split() | |
mode = parts[0] | |
if mode == '120000': | |
return True | |
return False | |
def readlink(self, path): | |
with io.open(path, 'r', encoding='utf-8') as file_: | |
return file_.read().rstrip() | |
def link(self, src, dst): | |
import win32file | |
win32file.CreateHardLink(dst, src) | |
def symlink(self, src, dst, repo_dir): | |
proc = subprocess.Popen( | |
['git', 'hash-object', '-w', '--stdin'], | |
stdin=subprocess.PIPE, | |
stdout=subprocess.PIPE) | |
sha1 = proc.communicate(src.encode())[0].decode().rstrip() | |
posix_dst = dst.replace('\\', '/') | |
subprocess.check_output( | |
[ | |
'git', 'update-index', '--add', '--cacheinfo', | |
'120000,{},{}'.format(sha1, posix_dst) | |
], | |
cwd=repo_dir) | |
env = dict(os.environ) | |
env['GIT_BIG_IGNORE_HOOK'] = '1' | |
subprocess.check_output( | |
['git', 'checkout', '--', dst], env=env, cwd=repo_dir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment