def get_tree(repo, tree_name): """ Get/create a tree-ish to be used for exporting and diffing. Accepts special keywords for git index and working copies. """ try: if tree_name == index_name: # Write a tree of the index tree = repo.write_tree() elif tree_name == wc_name: # Write a tree of the working copy tree = write_wc(repo) else: tree = tree_name except GitRepositoryError as err: raise GbpError(err) if not repo.has_treeish(tree): raise GbpError('Invalid treeish object %s' % tree) return tree
def write_tree(repo, options): """ Write a tree of the index or working copy if necessary @param repo: the git repository we're acting on @type repo: L{GitRepository} @return: the sha1 of the tree @rtype: C{str} """ if options.export_dir: if options.export == index_name: tree = repo.write_tree() elif options.export == wc_name: tree = write_wc(repo) else: tree = options.export if not repo.has_treeish(tree): raise GbpError # git-ls-tree printed an error message already else: tree = None return tree
def write_tree(repo, options): """ Write a tree of the index or working copy if necessary @param repo: the git repository we're acting on @type repo: L{GitRepository} @return: the sha1 of the tree @rtype: C{str} """ if options.export_dir: if options.export == index_name: tree = repo.write_tree() elif options.export == wc_name: tree = write_wc(repo) else: tree = options.export if not repo.has_treeish(tree): raise GbpError("%s is not a valid treeish" % tree) else: tree = None return tree
def maybe_write_tree(repo, options): """ Write a tree of the index or working copy if necessary @param repo: the git repository we're acting on @type repo: L{GitRepository} @return: the sha1 of the tree @rtype: C{str} """ if options.export_dir: if options.export == index_name: tree = repo.write_tree() elif options.export == wc_name: tree = write_wc(repo) else: tree = options.export if not repo.has_treeish(tree): raise GbpError("%s is not a valid treeish" % tree) else: tree = None return tree