Skip to content

Commit

Permalink
Teach (un)stage functions to behave on invalid args
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed May 2, 2024
1 parent fbaaf13 commit d69acfc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/git_mixins/stage_unstage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def stage_file(self, *fpath, force=True):
Given an absolute path or path relative to the repo's root, stage
the file.
"""
# Ensure we don't run "add --all" without any paths which
# would add everything
if not fpath:
return

self.git(
"add",
"-f" if force else None,
Expand All @@ -23,6 +28,11 @@ def unstage_file(self, *fpath):
Given an absolute path or path relative to the repo's root, unstage
the file.
"""
# Ensure we don't run "reset" without any paths which
# would unstage everything
if not fpath:
return

self.git("reset", "HEAD", "--", *fpath)

def add_all_tracked_files(self):
Expand All @@ -49,4 +59,9 @@ def intent_to_add(self, *file_paths: str) -> None:
self.git("add", "--intent-to-add", "--", *file_paths)

def undo_intent_to_add(self, *file_paths: str) -> None:
# Ensure we don't run "reset" without any paths which
# would unstage everything
if not file_paths:
return

self.git("reset", "--", *file_paths)

0 comments on commit d69acfc

Please sign in to comment.