浏览代码

HackStudio: Add functionality to GitRepo object

Added functionality for:
- Original files contents (without the current changes)
- Unstaged diffs
- Checking whether a file is tracked
Itamar 4 年之前
父节点
当前提交
ba11082b4b
共有 2 个文件被更改,包括 22 次插入0 次删除
  1. 19 0
      DevTools/HackStudio/Git/GitRepo.cpp
  2. 3 0
      DevTools/HackStudio/Git/GitRepo.h

+ 19 - 0
DevTools/HackStudio/Git/GitRepo.cpp

@@ -129,4 +129,23 @@ bool GitRepo::commit(const String& message)
 {
     return !command({ "commit", "-m", message }).is_null();
 }
+
+Optional<String> GitRepo::original_file_content(const LexicalPath& file) const
+{
+    return command({ "show", String::format("HEAD:%s", file.string().characters()) });
+}
+
+Optional<String> 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();
+}
+
 }

+ 3 - 0
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<String> original_file_content(const LexicalPath& file) const;
+    Optional<String> unstaged_diff(const LexicalPath& file) const;
+    bool is_tracked(const LexicalPath& file) const;
 
 private:
     static String command_wrapper(const Vector<String>& command_parts, const LexicalPath& chdir);