Skip to content

Commit e52ff1c

Browse files
committed
[WIP] Add command for tagging commit
1 parent 7995519 commit e52ff1c

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

asyncgit/src/sync/commit.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{get_head, utils::repo, CommitId};
22
use crate::error::Result;
3-
use git2::{ErrorCode, Repository, Signature};
3+
use git2::{ErrorCode, ObjectType, Repository, Signature};
44
use scopetime::scope_time;
55

66
///
@@ -80,6 +80,23 @@ pub fn commit(repo_path: &str, msg: &str) -> Result<CommitId> {
8080
.into())
8181
}
8282

83+
pub fn tag(
84+
repo_path: &str,
85+
commit_id: &CommitId,
86+
tag: &str,
87+
) -> Result<CommitId> {
88+
scope_time!("tag");
89+
90+
let repo = repo(repo_path)?;
91+
92+
let signature = signature_allow_undefined_name(&repo)?;
93+
let object_id = commit_id.get_oid();
94+
let target =
95+
repo.find_object(object_id, Some(ObjectType::Commit))?;
96+
97+
Ok(repo.tag(tag, &target, &signature, "", false)?.into())
98+
}
99+
83100
#[cfg(test)]
84101
mod tests {
85102

src/components/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub use inspect_commit::InspectCommitComponent;
3030
pub use msg::MsgComponent;
3131
pub use reset::ResetComponent;
3232
pub use stashmsg::StashMsgComponent;
33+
pub use textinput::TextInputComponent;
3334
pub use utils::filetree::FileTreeItemKind;
3435

3536
use crate::ui::style::Theme;

src/keys.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ pub const STASH_DROP: KeyEvent =
6666
with_mod(KeyCode::Char('D'), KeyModifiers::SHIFT);
6767
pub const CMD_BAR_TOGGLE: KeyEvent = no_mod(KeyCode::Char('.'));
6868
pub const LOG_COMMIT_DETAILS: KeyEvent = no_mod(KeyCode::Enter);
69+
pub const LOG_TAG_COMMIT: KeyEvent = no_mod(KeyCode::Char('t'));
6970
pub const COMMIT_AMEND: KeyEvent =
7071
with_mod(KeyCode::Char('a'), KeyModifiers::CONTROL);

src/strings.rs

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub static CONFIRM_MSG_STASHDROP: &str = "confirm stash drop?";
2727
pub static CONFIRM_MSG_RESETHUNK: &str = "confirm reset hunk?";
2828

2929
pub static LOG_TITLE: &str = "Commit";
30+
pub static LOG_TAG_COMMIT: &str = "type tag..";
31+
3032
pub static STASHLIST_TITLE: &str = "Stashes";
3133

3234
pub static HELP_TITLE: &str = "Help: all commands";
@@ -295,4 +297,7 @@ pub mod commands {
295297
"inspect selected commit in detail",
296298
CMD_GROUP_LOG,
297299
);
300+
///
301+
pub static LOG_TAG_COMMIT: CommandText =
302+
CommandText::new("Tag [t]", "tag commit", CMD_GROUP_LOG);
298303
}

src/tabs/revlog.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
components::{
33
visibility_blocking, CommandBlocking, CommandInfo,
44
CommitDetailsComponent, CommitList, Component,
5-
DrawableComponent,
5+
DrawableComponent, TextInputComponent,
66
},
77
keys,
88
queue::{InternalEvent, Queue},
@@ -28,6 +28,7 @@ const SLICE_SIZE: usize = 1200;
2828
///
2929
pub struct Revlog {
3030
commit_details: CommitDetailsComponent,
31+
tag_input: TextInputComponent,
3132
list: CommitList,
3233
git_log: AsyncLog,
3334
queue: Queue,
@@ -49,6 +50,11 @@ impl Revlog {
4950
sender,
5051
theme.clone(),
5152
),
53+
tag_input: TextInputComponent::new(
54+
theme.clone(),
55+
"",
56+
strings::LOG_TAG_COMMIT,
57+
),
5258
list: CommitList::new(strings::LOG_TITLE, theme),
5359
git_log: AsyncLog::new(sender),
5460
visible: false,
@@ -133,6 +139,10 @@ impl Revlog {
133139
fn selected_commit(&self) -> Option<CommitId> {
134140
self.list.selected_entry().map(|e| e.id)
135141
}
142+
143+
fn tag(&mut self) -> Result<()> {
144+
Ok(())
145+
}
136146
}
137147

138148
impl DrawableComponent for Revlog {
@@ -159,13 +169,19 @@ impl DrawableComponent for Revlog {
159169
self.list.draw(f, area)?;
160170
}
161171

172+
self.tag_input.draw(f, area)?;
173+
162174
Ok(())
163175
}
164176
}
165177

166178
impl Component for Revlog {
167179
fn event(&mut self, ev: Event) -> Result<bool> {
168180
if self.visible {
181+
if self.tag_input.event(ev)? {
182+
return Ok(true);
183+
}
184+
169185
let event_used = self.list.event(ev)?;
170186

171187
if event_used {
@@ -194,6 +210,11 @@ impl Component for Revlog {
194210
};
195211
}
196212

213+
Event::Key(keys::LOG_TAG_COMMIT) => {
214+
self.tag_input.show()?;
215+
return Ok(true);
216+
}
217+
197218
_ => (),
198219
}
199220
}
@@ -224,6 +245,12 @@ impl Component for Revlog {
224245
|| force_all,
225246
));
226247

248+
out.push(CommandInfo::new(
249+
commands::LOG_TAG_COMMIT,
250+
true,
251+
self.visible || force_all,
252+
));
253+
227254
visibility_blocking(self)
228255
}
229256

0 commit comments

Comments
 (0)