def test_file_only_copied(self): """Change by copying a file with no content editing""" ui = mock_ui() hgcommands.init(ui, self.repo) hgrepo = repository(ui, self.repo) ( open(hgrepo.pathto("file.dtd"), "w").write( """ <!ENTITY key1 "Hello"> <!ENTITY key2 "Cruel"> """ ) ) hgcommands.addremove(ui, hgrepo) hgcommands.commit(ui, hgrepo, user="******", message="initial commit") rev0 = hgrepo[0].hex() hgcommands.copy(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd")) hgcommands.commit(ui, hgrepo, user="******", message="Second commit") rev1 = hgrepo[1].hex() Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name) url = reverse("pushes.views.diff") response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1}) eq_(response.status_code, 200) html_diff = response.content.split("Changed files:")[1] ok_("copied from file.dtd" in re.sub("<.*?>", "", html_diff)) ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff)) ok_(not re.findall(">\s*Hello\s*<", html_diff)) ok_(not re.findall(">\s*Cruel\s*<", html_diff))
def copy(parent, ui, repo, files): assert len(files) == 1 wfile = repo.wjoin(files[0]) fd = QFileDialog(parent) fname = fd.getSaveFileName(parent, _("Copy file to"), wfile) if not fname: return fname = hglib.fromunicode(fname) wfiles = [wfile, fname] commands.copy(ui, repo, *wfiles) return True
def copy(parent, ui, repo, files): assert len(files) == 1 wfile = repo.wjoin(files[0]) fd = QFileDialog(parent) fname = fd.getSaveFileName(parent, _('Copy file to'), wfile) if not fname: return False fname = hglib.fromunicode(fname) wfiles = [wfile, fname] opts = {'force': True} # existing file is already checked by QFileDialog commands.copy(ui, repo, *wfiles, **opts) return True
def handle_copy(self, dest_path, depth_infinity): """Handle a COPY request natively.""" destType, destHgPath = util.pop_path(dest_path) destHgPath = destHgPath.strip("/") ui = self.provider.ui repo = self.provider.repo _logger.info("handle_copy %s -> %s" % (self.localHgPath, destHgPath)) if self.rev is None and destType == "edit": # COPY /edit/a/b to /edit/c/d: turn into 'hg copy -f a/b c/d' commands.copy(ui, repo, self.localHgPath, destHgPath, force=True) elif self.rev is None and destType == "released": # COPY /edit/a/b to /released/c/d # This is interpreted as 'hg commit a/b' (ignoring the dest. path) self._commit("WsgiDAV commit (COPY %s -> %s)" % (self.path, dest_path)) else: raise DAVError(HTTP_FORBIDDEN) # Return True: request was handled return True
def handleCopy(self, destPath, depthInfinity): """Handle a COPY request natively. """ destType, destHgPath = util.popPath(destPath) destHgPath = destHgPath.strip("/") ui = self.provider.ui repo = self.provider.repo util.write("handleCopy %s -> %s" % (self.localHgPath, destHgPath)) if self.rev is None and destType == "edit": # COPY /edit/a/b to /edit/c/d: turn into 'hg copy -f a/b c/d' commands.copy(ui, repo, self.localHgPath, destHgPath, force=True) elif self.rev is None and destType == "released": # COPY /edit/a/b to /released/c/d # This is interpreted as 'hg commit a/b' (ignoring the dest. path) self._commit("WsgiDAV commit (COPY %s -> %s)" % (self.path, destPath)) else: raise DAVError(HTTP_FORBIDDEN) # Return True: request was handled return True
def test_file_copied_and_edited_original_broken(self): """Change by copying a broken file""" ui = mock_ui() hgcommands.init(ui, self.repo) hgrepo = repository(ui, self.repo) ( codecs.open(hgrepo.pathto("file.dtd"), "w", "latin1").write( u""" <!ENTITY key1 "Hell\xe3"> <!ENTITY key2 "Cruel"> """ ) ) hgcommands.addremove(ui, hgrepo) hgcommands.commit(ui, hgrepo, user="******", message="initial commit") rev0 = hgrepo[0].hex() hgcommands.copy(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd")) ( open(hgrepo.pathto("newnamefile.dtd"), "w").write( """ <!ENTITY key1 "Hello"> <!ENTITY key2 "World"> """ ) ) hgcommands.commit(ui, hgrepo, user="******", message="Second commit") rev1 = hgrepo[1].hex() Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name) url = reverse("pushes.views.diff") response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1}) eq_(response.status_code, 200) html_diff = response.content.split("Changed files:")[1].split("page_footer")[0] html_diff = unicode(html_diff, "utf-8") ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff)) ok_("Cannot parse file" in html_diff) eq_(html_diff.count("Cannot parse file"), 1)
def dohgcopy(): commands.copy(self.stat.ui, self.stat.repo, *wfiles, **cmdopts)
def subpull(ui, repo, name='', **opts): """Pull subtree(s)""" # change to root directory if repo.getcwd() != '': ui.warn( "Working directory is not repository root. At best, this directory won't exist when subpull is done.\n" ) repo.dirstate._cwd = repo.root os.chdir(repo.root) # if there are uncommitted change, abort --- we will be modifying the working copy quite drammatically modified, added, removed, deleted, _unknown, _ignored, _clean = repo.status( ) if modified or added or removed or deleted: raise error.Abort( "Uncommitted changes in the working copy. Subtree extension needs to modify the working copy, so it cannot proceed." ) # parse .hgsubtree hgsubtree = ui.config('subtree', 'hgsubtree', default=default_hgsubtree) subtrees = _parse_hgsubtree(os.path.join(repo.root, hgsubtree)) # if names not in .hgsubtree, abort # if names is empty, go through all repos in .hgsubtree if name: if name not in subtrees: raise error.Abort("Cannot find %s in %s." % (name, hgsubtree)) names = [name] else: if opts['source']: raise error.Abort( "Cannot use --source without specifying a repository") names = subtrees.keys() null = repo['null'] origin = str(repo[None]) commit_opts = {'edit': opts['edit']} bookmark_prefix = ui.config('subtree', 'bookmark', default=default_bookmark_prefix) nocache = ui.config('subtree', 'nocache', default='') for name in names: subtree = subtrees[name] if 'destination' not in subtree: raise error.Abort('No destination found for %s' % name) collapse = 'collapse' in subtree and subtree['collapse'] # figure out the revision to pull pull_opts = {} if 'rev' in subtree: pull_opts['rev'] = [subtree['rev']] if opts['rev']: pull_opts['rev'] = opts['rev'] # clone or pull into cache source = subtree['source'] if not opts['source'] else opts['source'] if not nocache: source = _clone_or_pull(ui, repo, name, source, pull_opts) # pull tip = repo['tip'] commands.pull(ui, repo, source=source, force=True, **pull_opts) if tip == repo['tip']: ui.status("no changes: nothing for subtree to do\n") continue # collapse or update -C if collapse: # find a matching bookmark bookmark_name = bookmark_prefix + name if bookmark_name in repo._bookmarks: commands.update(ui, repo, bookmark_name, clean=True) else: commands.update(ui, repo, 'null', clean=True) # set up the correct file state and commit as a new changeset pulled_tip = repo['tip'] commands.revert(ui, repo, rev='tip', all=True) hgsubrepo_meta = [ os.path.join(repo.root, '.hgsubstate'), os.path.join(repo.root, '.hgsub') ] for fn in hgsubrepo_meta: if os.path.exists(fn): ui.debug("removing %s\n" % fn) commands.remove(ui, repo, fn, force=True) os.remove(fn) changed = commands.commit(ui, repo, message=ui.config( 'subtree', 'collapse', default_collapse_comment).format( name=name, rev=str(pulled_tip)[:12]), **commit_opts) commands.bookmark(ui, repo, bookmark_name, inactive=True) if not opts['no_strip']: # delete bookmarks on the changesets that will be stripped; not # the most efficient procedure to find them, but will do for now remove_bookmarks = [] for k in repo._bookmarks.keys(): ctx = repo[k] if pulled_tip.ancestor(ctx) != null: remove_bookmarks.append(k) for bookmark in remove_bookmarks: commands.bookmark(ui, repo, bookmark, delete=True) strip.stripcmd(ui, repo, rev=['ancestors(%s)' % str(pulled_tip)], bookmark=[]) if changed == 1: # nothing changed ui.status("no changes: nothing for subtree to do\n") commands.update(ui, repo, origin[:12]) continue else: commands.update(ui, repo, 'tip', clean=True) # move or delete destinations = _destinations(subtree['destination']) # process destinations keep_list = [] for dest in destinations: if dest[0] == 'mkdir': if not os.path.exists(dest[1]): os.makedirs(dest[1]) elif dest[0] == 'mv': commands.rename(ui, repo, *dest[1:], force=False) elif dest[0] == 'cp': commands.copy(ui, repo, *dest[1:], force=False) elif dest[0] == 'rm': commands.remove(ui, repo, *dest[1:], force=False) elif dest[0] == 'keep': keep_list.append(' '.join(dest[1:])) # remove all untouched files, unless instructed to keep them if 'keep' not in subtree or not subtree['keep']: _modified, _added, _removed, _deleted, _unknown, _ignored, clean = repo.status( clean=True) for fn in clean: for keep_pattern in keep_list: if fnmatch(fn, keep_pattern): break else: commands.remove(ui, repo, fn) commands.commit( ui, repo, message=ui.config('subtree', 'move', default_move_comment).format(name=name), **commit_opts) merge_commit = str(repo[None]) # update to original and merge with the new commands.update(ui, repo, origin[:12]) commands.merge(ui, repo, merge_commit[:12]) commands.commit( ui, repo, message=ui.config('subtree', 'merge', default_merge_comment).format(name=name), **commit_opts) origin = str(repo[None])