mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 10:41:30 +00:00
HackStudio: Add functionality to GitRepo object
Added functionality for: - Original files contents (without the current changes) - Unstaged diffs - Checking whether a file is tracked
This commit is contained in:
parent
8306a84967
commit
ba11082b4b
Notes:
sideshowbarker
2024-07-19 02:23:52 +09:00
Author: https://github.com/itamar8910
Commit: ba11082b4b
Pull-request: https://github.com/SerenityOS/serenity/pull/3470
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
Reviewed-by: https://github.com/devsh0
2 changed files with 22 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue