Skip to content

Commit

Permalink
Track repo differences with git status rather than git diff
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Oct 23, 2024
1 parent 1a1e311 commit 363f290
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
16 changes: 12 additions & 4 deletions cilib/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sh
import re
from subprocess import run
from typing import Dict
from .github_api import Repository
import requests
import requests.auth
Expand Down Expand Up @@ -69,11 +70,18 @@ def add(files, **subprocess_kwargs):
run(["git", "add", fn], **subprocess_kwargs)


def diff(**subprocess_kwargs):
"""Diff git repo"""
cmd = ["git", "diff", "--name-only"]
def status(**subprocess_kwargs) -> Dict[str, str]:
"""Show any uncommitted files in a git repo.
Returns:
Dict[str, str]: A dictionary of uncommitted files and their status.
key values are the file names and the values are the status of the file.
https://git-scm.com/docs/git-status
"""
cmd = ["git", "status", "--porcelain"]
output = run(cmd, capture_output=True, text=True, **subprocess_kwargs)
return [line for line in output.stdout.splitlines()]
return dict(reversed(line.split(maxsplit=1)) for line in output.stdout.splitlines())


def commit(message, **subprocess_kwargs):
Expand Down
4 changes: 2 additions & 2 deletions cilib/models/repos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def add(self, files, **subprocess_kwargs):
"""Add files to git repo"""
git.add(files, **subprocess_kwargs)

def diff(self, **subprocess_kwargs):
def status(self, **subprocess_kwargs):
"""Diff git repo"""
return git.diff(**subprocess_kwargs)
return git.status(**subprocess_kwargs)

@sham
def push(self, origin="origin", ref="master", **subprocess_kwargs):
Expand Down
2 changes: 1 addition & 1 deletion cilib/service/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def template_snapcraft_yml(
snapcraft_yml = self.render(snapcraft_fn_tpl, snapcraft_yml_context)
snapcraft_fn.write_text(snapcraft_yml)

if self.snap_model.base.diff(cwd=str(src_path)):
if self.snap_model.base.status(cwd=str(src_path)):
self.log(f"Committing {branch}")
self.snap_model.base.add([str(snapcraft_fn)], cwd=str(src_path))
self.snap_model.base.commit(f"{commit_msg} {branch}", cwd=str(src_path))
Expand Down

0 comments on commit 363f290

Please sign in to comment.