Skip to content

Commit 5c9e9ba

Browse files
committed
feat: Improve default handling for CommitSaver
- Enhance error handling in CommitSaver by providing defaults for missing remote or branch details - Introduce fallback strings "no_url_set" and "no_branch_set" for scenarios where remote or branch information is absent
1 parent 8c01a90 commit 5c9e9ba

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/vim_commit.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,20 @@ impl Default for CommitSaver {
145145
let commit = head.peel_to_commit().unwrap();
146146
CommitSaver {
147147
repository_url: {
148-
let bind = git_repo.find_remote("origin").unwrap();
149-
bind.url().unwrap().replace('\"', "")
148+
let url = match git_repo.find_remote("origin") {
149+
Ok(bind) => bind.url().unwrap().replace('\"', ""),
150+
_ => "no_url_set".to_string(),
151+
};
152+
url
153+
},
154+
commit_branch_name: {
155+
// head.shorthand().unwrap().replace('\"', "")
156+
let branch = match head.shorthand() {
157+
Some(branch) => branch.replace('\"', ""),
158+
None => "no_branch_set".to_string(),
159+
};
160+
branch
150161
},
151-
commit_branch_name: { head.shorthand().unwrap().replace('\"', "") },
152162
commit_hash: { commit.id().to_string() },
153163
commit_msg: {
154164
// Preserve original lines, escape pipes, then join with <br/>

0 commit comments

Comments
 (0)