git_utils.py 562 B

123456789101112131415161718192021222324
  1. from git import Repo
  2. import streamlit as st
  3. def show_git_diff():
  4. """
  5. Shows the current git diff in the working directory.
  6. Returns the diff as a string or None if there are no changes.
  7. """
  8. try:
  9. # Get git diff using GitPython
  10. repo = Repo(".")
  11. diff = repo.git.diff()
  12. if diff:
  13. st.write(diff)
  14. return diff
  15. else:
  16. st.error("Failed to show git diff")
  17. return None
  18. except Exception as e:
  19. st.error(f"Error getting git diff: {e}")
  20. return None