##// END OF EJS Templates
When applying a git diff, ensure that the target dir exists for new files
Stefan Rusek -
r7505:fe0e02f9 default
parent child Browse files
Show More
@@ -22,17 +22,20 b' class NoHunks(PatchError):'
22
22
23 # helper functions
23 # helper functions
24
24
25 def copyfile(src, dst, basedir=None):
25 def copyfile(src, dst, basedir):
26 if not basedir:
26 abssrc, absdst = [util.canonpath(basedir, basedir, x) for x in [src, dst]]
27 basedir = os.getcwd()
28
29 abssrc, absdst = [os.path.join(basedir, n) for n in (src, dst)]
30 if os.path.exists(absdst):
27 if os.path.exists(absdst):
31 raise util.Abort(_("cannot create %s: destination already exists") %
28 raise util.Abort(_("cannot create %s: destination already exists") %
32 dst)
29 dst)
33
30
34 if not os.path.isdir(basedir):
31 dstdir = os.path.dirname(absdst)
35 os.makedirs(basedir)
32 if dstdir and not os.path.isdir(dstdir):
33 try:
34 os.makedirs(dstdir)
35 except:
36 raise util.Abort(
37 _("cannot create %s: unable to create destination directory")
38 % dst)
36
39
37 util.copyfile(abssrc, absdst)
40 util.copyfile(abssrc, absdst)
38
41
@@ -977,9 +980,7 b' def applydiff(ui, fp, changed, strip=1, '
977 cwd = os.getcwd()
980 cwd = os.getcwd()
978 for gp in gitpatches:
981 for gp in gitpatches:
979 if gp.op in ('COPY', 'RENAME'):
982 if gp.op in ('COPY', 'RENAME'):
980 src, dst = [util.canonpath(cwd, cwd, x)
983 copyfile(gp.oldpath, gp.path, cwd)
981 for x in [gp.oldpath, gp.path]]
982 copyfile(src, dst)
983 changed[gp.path] = gp
984 changed[gp.path] = gp
984 else:
985 else:
985 raise util.Abort(_('unsupported parser state: %s') % state)
986 raise util.Abort(_('unsupported parser state: %s') % state)
General Comments 0
You need to be logged in to leave comments. Login now