diff --git a/DevTools/HackStudio/Git/GitRepo.cpp b/DevTools/HackStudio/Git/GitRepo.cpp index 3461dacbf2..96b370e568 100644 --- a/DevTools/HackStudio/Git/GitRepo.cpp +++ b/DevTools/HackStudio/Git/GitRepo.cpp @@ -129,4 +129,23 @@ bool GitRepo::commit(const String& message) { return !command({ "commit", "-m", message }).is_null(); } + +Optional GitRepo::original_file_content(const LexicalPath& file) const +{ + return command({ "show", String::format("HEAD:%s", file.string().characters()) }); +} + +Optional GitRepo::unstaged_diff(const LexicalPath& file) const +{ + return command({ "diff", file.string().characters() }); +} + +bool GitRepo::is_tracked(const LexicalPath& file) const +{ + auto res = command({ "ls-files", file.string() }); + if (res.is_null()) + return false; + return !res.is_empty(); +} + } diff --git a/DevTools/HackStudio/Git/GitRepo.h b/DevTools/HackStudio/Git/GitRepo.h index 5f17e46dcb..03037b224a 100644 --- a/DevTools/HackStudio/Git/GitRepo.h +++ b/DevTools/HackStudio/Git/GitRepo.h @@ -55,6 +55,9 @@ public: bool stage(const LexicalPath& file); bool unstage(const LexicalPath& file); bool commit(const String& message); + Optional original_file_content(const LexicalPath& file) const; + Optional unstaged_diff(const LexicalPath& file) const; + bool is_tracked(const LexicalPath& file) const; private: static String command_wrapper(const Vector& command_parts, const LexicalPath& chdir);