Skip to content

Commit 71f7cf2

Browse files
committed
Add debugging utilities
1 parent 015595c commit 71f7cf2

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ gitbutler-forge = { path = "crates/gitbutler-forge" }
6666
gitbutler-hunk-dependency = { path = "crates/gitbutler-hunk-dependency" }
6767
gitbutler-settings = { path = "crates/gitbutler-settings" }
6868
gitbutler-workspace = { path = "crates/gitbutler-workspace" }
69+
but-debugging = { path = "crates/but-debugging" }
6970
but-core = { path = "crates/but-core" }
7071
but-workspace = { path = "crates/but-workspace" }
7172

crates/but-debugging/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "but-debugging"
3+
version = "0.0.0"
4+
edition = "2021"
5+
authors = ["GitButler <[email protected]>"]
6+
publish = false
7+
8+
[lib]
9+
doctest = false
10+
11+
[dependencies]
12+
13+
[dev-dependencies]

crates/but-debugging/src/lib.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
use std::{path::Path, process::Command};
2+
3+
pub struct LogOptions {
4+
pub oneline: bool,
5+
pub graph: bool,
6+
pub all: bool,
7+
pub reference: String,
8+
}
9+
10+
impl Default for LogOptions {
11+
fn default() -> Self {
12+
Self {
13+
oneline: true,
14+
graph: true,
15+
all: false,
16+
reference: "HEAD".to_string(),
17+
}
18+
}
19+
}
20+
21+
impl LogOptions {
22+
pub fn oneline(&mut self, oneline: bool) -> &mut Self {
23+
self.oneline = oneline;
24+
self
25+
}
26+
27+
pub fn graph(&mut self, graph: bool) -> &mut Self {
28+
self.graph = graph;
29+
self
30+
}
31+
32+
pub fn reference(&mut self, reference: String) -> &mut Self {
33+
self.reference = reference;
34+
self
35+
}
36+
37+
pub fn all(&mut self, all: bool) -> &mut Self {
38+
self.all = all;
39+
self
40+
}
41+
}
42+
43+
pub fn git_log(path: &Path, options: &LogOptions) {
44+
let path = if path.ends_with(".git") {
45+
path.parent().unwrap()
46+
} else {
47+
path
48+
};
49+
let mut command = Command::new("git");
50+
command.current_dir(path);
51+
command.arg("log");
52+
if options.oneline {
53+
command.arg("--oneline");
54+
}
55+
if options.graph {
56+
command.arg("--graph");
57+
}
58+
if options.all {
59+
command.arg("--all");
60+
}
61+
command.arg(options.reference.clone());
62+
let result = command.output().unwrap().stdout;
63+
println!("{:?}", command);
64+
println!("{}", std::str::from_utf8(&result).unwrap());
65+
}
66+
67+
pub struct LsTreeOptions {
68+
pub recursive: bool,
69+
pub reference: String,
70+
}
71+
72+
impl Default for LsTreeOptions {
73+
fn default() -> Self {
74+
Self {
75+
recursive: true,
76+
reference: "HEAD".to_string(),
77+
}
78+
}
79+
}
80+
81+
impl LsTreeOptions {
82+
pub fn recursive(&mut self, recursive: bool) -> &mut Self {
83+
self.recursive = recursive;
84+
self
85+
}
86+
87+
pub fn reference(&mut self, reference: String) -> &mut Self {
88+
self.reference = reference;
89+
self
90+
}
91+
}
92+
93+
pub fn git_ls_tree(path: &Path, options: &LsTreeOptions) {
94+
let path = if path.ends_with(".git") {
95+
path.parent().unwrap()
96+
} else {
97+
path
98+
};
99+
let mut command = Command::new("git");
100+
command.current_dir(path);
101+
command.arg("ls-tree");
102+
if options.recursive {
103+
command.arg("-r");
104+
}
105+
command.arg(options.reference.clone());
106+
let result = command.output().unwrap().stdout;
107+
println!("{:?}", command);
108+
println!("{}", std::str::from_utf8(&result).unwrap());
109+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

crates/gitbutler-branch-actions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ urlencoding = "2.1.3"
4949
reqwest = { version = "0.12.9", features = ["json"] }
5050
toml.workspace = true
5151
uuid.workspace = true
52+
but-debugging.workspace = true
5253

5354
[dev-dependencies]
5455
once_cell = "1.20"

0 commit comments

Comments
 (0)