From df1ff6d1dad08c6317af5495ecc09736a6259c1a Mon Sep 17 00:00:00 2001 From: Sainath Singineedi Date: Wed, 21 Feb 2024 00:37:21 +0530 Subject: [PATCH 1/4] feat: add branch name validation on renaming --- CHANGELOG.md | 3 ++- src/popups/rename_branch.rs | 43 ++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9c6ade06..bf875888bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,10 +25,11 @@ These defaults require some adoption from existing users but feel more natural t * add syntax highlighting for blame view [[@tdtrung17693](https://github.com/tdtrung17693)] ([#745](https://github.com/extrawurst/gitui/issues/745)) * allow aborting pending commit log search [[@StemCll](https://github.com/StemCll)] ([#1860](https://github.com/extrawurst/gitui/issues/1860)) * `theme.ron` now supports customizing line break symbol ([#1894](https://github.com/extrawurst/gitui/issues/1894)) -* add confirmation for dialog for undo commit [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1912](https://github.com/extrawurst/gitui/issues/1912)) +* add confirmation for dialog for undo commit [[@sainad2222](https://github.com/sainad2222)] ([#1912](https://github.com/extrawurst/gitui/issues/1912)) * support `prepare-commit-msg` hook ([#1873](https://github.com/extrawurst/gitui/issues/1873)) * new style `block_title_focused` to allow customizing title text of focused frame/block ([#2052](https://github.com/extrawurst/gitui/issues/2052)). * allow `fetch` command in both tabs of branchlist popup ([#2067](https://github.com/extrawurst/gitui/issues/2067)) +* check branch name validity while typing [[@sainad2222](https://github.com/sainad2222)] ([#2062](https://github.com/extrawurst/gitui/issues/2062)) ### Changed * do not allow tagging when `tag.gpgsign` enabled until gpg-signing is [supported](https://github.com/extrawurst/gitui/issues/97) [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1915](https://github.com/extrawurst/gitui/pull/1915)) diff --git a/src/popups/rename_branch.rs b/src/popups/rename_branch.rs index d82434173d..bf8e7974f0 100644 --- a/src/popups/rename_branch.rs +++ b/src/popups/rename_branch.rs @@ -2,6 +2,7 @@ use crate::components::{ visibility_blocking, CommandBlocking, CommandInfo, Component, DrawableComponent, EventState, InputType, TextInputComponent, }; +use crate::ui::style::SharedTheme; use crate::{ app::Environment, keys::{key_match, SharedKeyConfig}, @@ -11,7 +12,8 @@ use crate::{ use anyhow::Result; use asyncgit::sync::{self, RepoPathRef}; use crossterm::event::Event; -use ratatui::{layout::Rect, Frame}; +use easy_cast::Cast; +use ratatui::{layout::Rect, widgets::Paragraph, Frame}; pub struct RenameBranchPopup { repo: RepoPathRef, @@ -19,12 +21,15 @@ pub struct RenameBranchPopup { branch_ref: Option, queue: Queue, key_config: SharedKeyConfig, + theme: SharedTheme, } impl DrawableComponent for RenameBranchPopup { fn draw(&self, f: &mut Frame, rect: Rect) -> Result<()> { - self.input.draw(f, rect)?; - + if self.is_visible() { + self.input.draw(f, rect)?; + self.draw_warnings(f); + } Ok(()) } } @@ -97,6 +102,7 @@ impl RenameBranchPopup { .with_input_type(InputType::Singleline), branch_ref: None, key_config: env.key_config.clone(), + theme: env.theme.clone(), } } @@ -148,4 +154,35 @@ impl RenameBranchPopup { self.input.clear(); } + + fn draw_warnings(&self, f: &mut Frame) { + let current_text = self.input.get_text(); + + if !current_text.is_empty() { + let valid = sync::validate_branch_name(current_text) + .unwrap_or_default(); + + if !valid { + let msg = strings::branch_name_invalid(); + let msg_length: u16 = msg.len().cast(); + let w = Paragraph::new(msg) + .style(self.theme.text_danger()); + + let rect = { + let mut rect = self.input.get_area(); + rect.y += rect.height.saturating_sub(1); + rect.height = 1; + let offset = + rect.width.saturating_sub(msg_length + 1); + rect.width = + rect.width.saturating_sub(offset + 1); + rect.x += offset; + + rect + }; + + f.render_widget(w, rect); + } + } + } } From c035330414bf2a5f08e463e8f6b3792608deb0fe Mon Sep 17 00:00:00 2001 From: Sainath Singineedi Date: Wed, 21 Feb 2024 00:57:24 +0530 Subject: [PATCH 2/4] fix: panic because of python3 --- git2-hooks/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git2-hooks/src/lib.rs b/git2-hooks/src/lib.rs index ea7842cc4e..dd4844f331 100644 --- a/git2-hooks/src/lib.rs +++ b/git2-hooks/src/lib.rs @@ -439,7 +439,7 @@ exit 1 // mirror how python pre-commmit sets itself up #[cfg(not(windows))] - let hook = b"#!/usr/bin/env python + let hook = b"#!/usr/bin/env python3 import sys sys.exit(0) "; From ebcf2622cd756ecd4f96957f6758b11af202b521 Mon Sep 17 00:00:00 2001 From: extrawurst <776816+extrawurst@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:42:12 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf875888bf..9a0646d2cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ These defaults require some adoption from existing users but feel more natural t * add syntax highlighting for blame view [[@tdtrung17693](https://github.com/tdtrung17693)] ([#745](https://github.com/extrawurst/gitui/issues/745)) * allow aborting pending commit log search [[@StemCll](https://github.com/StemCll)] ([#1860](https://github.com/extrawurst/gitui/issues/1860)) * `theme.ron` now supports customizing line break symbol ([#1894](https://github.com/extrawurst/gitui/issues/1894)) -* add confirmation for dialog for undo commit [[@sainad2222](https://github.com/sainad2222)] ([#1912](https://github.com/extrawurst/gitui/issues/1912)) +* add confirmation for dialog for undo commit [[@TeFiLeDo](https://github.com/TeFiLeDo)] ([#1912](https://github.com/extrawurst/gitui/issues/1912)) * support `prepare-commit-msg` hook ([#1873](https://github.com/extrawurst/gitui/issues/1873)) * new style `block_title_focused` to allow customizing title text of focused frame/block ([#2052](https://github.com/extrawurst/gitui/issues/2052)). * allow `fetch` command in both tabs of branchlist popup ([#2067](https://github.com/extrawurst/gitui/issues/2067)) From 6771343ec5e4978b694041d1963673cc4ea74b8d Mon Sep 17 00:00:00 2001 From: extrawurst <776816+extrawurst@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:18:56 +0100 Subject: [PATCH 4/4] Update lib.rs lets not do this as on CI everything works fine. never change a running system --- git2-hooks/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git2-hooks/src/lib.rs b/git2-hooks/src/lib.rs index dd4844f331..ea7842cc4e 100644 --- a/git2-hooks/src/lib.rs +++ b/git2-hooks/src/lib.rs @@ -439,7 +439,7 @@ exit 1 // mirror how python pre-commmit sets itself up #[cfg(not(windows))] - let hook = b"#!/usr/bin/env python3 + let hook = b"#!/usr/bin/env python import sys sys.exit(0) ";