2
0

porcelain.txt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Porcelain
  2. =========
  3. The ``porcelain`` is the higher level interface, built on top of the lower
  4. level implementation covered in previous chapters of this tutorial. The
  5. ``dulwich.porcelain`` module in Dulwich is aimed to closely resemble
  6. the Git command-line API that you are familiar with.
  7. Basic concepts
  8. --------------
  9. The porcelain operations are implemented as top-level functions in the
  10. ``dulwich.porcelain`` module. Most arguments can either be strings or
  11. more complex Dulwich objects; e.g. a repository argument will either take
  12. a string with a path to the repository or an instance of a ``Repo`` object.
  13. Initializing a new repository
  14. -----------------------------
  15. >>> from dulwich import porcelain
  16. >>> repo = porcelain.init("myrepo")
  17. Clone a repository
  18. ------------------
  19. >>> porcelain.clone("git://github.com/jelmer/dulwich", "dulwich-clone")
  20. Basic authentication works using the ``username`` and ``password`` parameters:
  21. >>> porcelain.clone(
  22. "https://example.com/a-private-repo.git",
  23. "a-private-repo-clone",
  24. username="user", password="password")
  25. Commit changes
  26. --------------
  27. >>> r = porcelain.init("testrepo")
  28. >>> open("testrepo/testfile", "w").write("data")
  29. >>> porcelain.add(r, "testfile")
  30. >>> porcelain.commit(r, b"A sample commit")
  31. Push changes
  32. ------------
  33. >>> tr = porcelain.init("targetrepo")
  34. >>> r = porcelain.push("testrepo", "targetrepo", "master")