Skip to content

Instantly share code, notes, and snippets.

@revirth
Last active December 11, 2015 08:58
Show Gist options
  • Save revirth/4577014 to your computer and use it in GitHub Desktop.
Save revirth/4577014 to your computer and use it in GitHub Desktop.
Copy Untracked Files
@echo off
cd %1
git ls-files -m > %2.txt
echo 'done' %2.txt
# -*- coding: utf-8 -*-
import subprocess, sys, time, os, shutil
if len(sys.argv) < 3:
print u"usage : CopyUntrackedFiles.py SourceDirectory TargetDirectory", len(sys.argv)
exit()
sourceDIR = sys.argv[1]
targetDIR = sys.argv[2]
# make a text file for untracked files
untrackedFileList = time.strftime("%Y%m%d-%H%M%S", time.localtime(time.time()))
subprocess.call('CopyUntrackedFiles.bat "'+sys.argv[1]+'" ' + untrackedFileList)
# read untracked file list
with open(sourceDIR + '\' + untrackedFileList + '.txt', 'r+') as f:
filelist = f.read().split('n')
f.close()
for sf in filelist:
if(len(sf) > 0):
# make folders
folder = targetDIR + '\' + sf[:sf.rindex('/')]
if not os.path.exists(folder):
os.makedirs(folder)
# copy source files wtih metadata
shutil.copy2(sourceDIR + '\' + sf, folder)
# delete the text file
os.remove(sourceDIR + '\' + untrackedFileList + '.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment