Skip to content

Commit

Permalink
Release version 0.0.0.dev45
Browse files Browse the repository at this point in the history
  • Loading branch information
AAriam committed Oct 3, 2024
1 parent 87d818e commit b2720f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespaces = true
# ----------------------------------------- Project Metadata -------------------------------------
#
[project]
version = "0.0.0.dev44"
version = "0.0.0.dev45"
name = "GitTidy"
requires-python = ">=3.10"
dependencies = [
Expand Down
36 changes: 35 additions & 1 deletion src/gittidy/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ def create_tag(
self.push(target=push_target, ref=tag)
return out

def has_changes(self, check_type: _Literal["staged", "unstaged", "all"] = "all") -> bool:
def has_changes(
self,
check_type: _Literal["staged", "unstaged", "all"] = "all",
path: str | None = None,
) -> bool:
"""Checks for git changes.
Parameters:
Expand All @@ -261,6 +265,8 @@ def has_changes(self, check_type: _Literal["staged", "unstaged", "all"] = "all")
- bool: True if changes are detected, False otherwise.
"""
commands = {"staged": ["diff", "--quiet", "--cached"], "unstaged": ["diff", "--quiet"]}
if path:
commands = {k: [*v, path] for k, v in commands.items()}
if check_type == "all":
return any(
self.run_command(
Expand All @@ -279,6 +285,34 @@ def has_changes(self, check_type: _Literal["staged", "unstaged", "all"] = "all")
stack_up=1,
).code != 0

def restore(
self,
path: str,
change_type: _Literal["staged", "unstaged", "all"] = "all",
source: str | None = None,
):
"""Restore changes in git.
Parameters:
- change_type (str): Can be 'staged', 'unstaged', or 'all'. Default is 'all'.
"""
cmd = ["restore", "--progress"]
if source:
cmd.extend(["--source", source])
if change_type == "all":
cmd.extend(["--staged", "--worktree"])
elif change_type == "staged":
cmd.append("--staged")
else:
cmd.append("--worktree")
cmd.append(path)
self.run_command(
cmd,
log_title="Git: Restore Changes",
stack_up=1,
)
return

def changed_files(self, ref_start: str, ref_end: str) -> dict[str, list[str]]:
"""
Get all files that have changed between two commits, and the type of changes.
Expand Down

0 comments on commit b2720f3

Please sign in to comment.