def fix_symlinks(ui, repo, hooktype, parent1, **kwargs): revert = hooktype in ('precommit', 'preupdate') ctxt = repo[parent1] for filename in ctxt: file = ctxt[filename] if 'l' in file.flags(): path = repo.wjoin(file.path()) try: os.unlink(path) except Exception, e: print repr(e) if revert: repo.wwrite(file.path(), file.data(), '') else: target = os.path.join(os.path.dirname(path), file.data()) util.copyfiles(target, path, True)
def postinitskel(ui, repo, hooktype, result, pats, **kwargs): """create common files in new repository""" assert hooktype == 'post-init' if result: return dest = ui.expandpath(pats and pats[0] or '.') skel = ui.config('tortoisehg', 'initskel') if skel: # copy working tree from user-defined path if any skel = util.expandpath(skel) for name in os.listdir(skel): if name == '.hg': continue util.copyfiles(os.path.join(skel, name), os.path.join(dest, name), hardlink=False) return # create .hg* files, mainly to workaround Explorer's problem in creating # files with a name beginning with a dot open(os.path.join(dest, '.hgignore'), 'a').close()
def localbranch(self, name): # switch to local branch, creating if necessary def checkdir(d): if not os.path.isdir(d): if os.path.exists(d): raise util.Abort(_('%s is not a directory') % d) return False return True if self.dirstate.parents()[1] != nullid: raise util.Abort(_('merge in progress')) obranch = self.getlocalbranch() lname = encoding.fromlocal(name) if obranch == name: return omf = self.changectx('').manifest() del self.changelog del self.manifest if not name: lbpath = self.join('localbranch') if os.path.exists(lbpath): os.unlink(lbpath) else: bdir = self.join('branches') if not checkdir(bdir): os.mkdir(bdir) dest = os.path.join(bdir, store.encodefilename(lname)) if not checkdir(dest): # check for non-store layout if self.spath == self.path: os.mkdir(dest) datadir = os.path.join(dest, 'data') util.copyfiles(self.join('data'), datadir) for f in ('00changelog.i', '00changelog.d', '00manifest.i', '00manifest.d'): src = self.join(f) if os.path.exists(src): util.copyfiles(src, os.path.join(dest, f)) else: os.mkdir(dest) spath = os.path.join(dest, 'store') util.copyfiles(self.spath, spath) self.opener('localbranch', 'w').write(lname + '\n') self.loadlocalbranch(name) ctx = repo.changectx('tip') wlock = self.wlock() try: self.refreshdirstate(ctx, omf) finally: wlock.release()