Skip to content

Commit

Permalink
Add alert or warning when reset or reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
malaise committed Sep 5, 2023
1 parent e4e3348 commit 3d3a548
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 31 deletions.
11 changes: 6 additions & 5 deletions usr/agite/Agite.txt
@@ -1,6 +1,6 @@
Agite user guide
================
V42.06
V42.07

General purpose
---------------
Expand Down Expand Up @@ -2218,10 +2218,11 @@ the history of the current branch (which is reset).
* The 'Delete' function of the xref:XReflog[reflog] menu also rewrites the
history.

The confirmation menu for these actions warns you (in red) that the history
will be rewritten. +
Besides, the xref:XHist[history] menu on root sets the
initial entry to the head of the corresponding tracking branch, which should
The confirmation menu for these actions alerts you (in red) that the history
will be rewritten and has been pushed, or warns you (in orange) that the
local history will be modified. +
Besides, the "RemHd" button of the xref:XHist[history] menu sets the
current entry to the head of the corresponding tracking branch, which should
be a safe reference for a xref:XReorg[reorg] or xref:XReset[reset]. When the
reference is set to below (before) the head of the remote, then these both
buttons become red. +
Expand Down
7 changes: 5 additions & 2 deletions usr/agite/branch-rebase_mng.adb
Expand Up @@ -41,7 +41,8 @@ package body Rebase_Mng is
-- Rebase current branch to head of Reference
function Do_Rebase (Root : String;
Target_Branch, Reference_Branch: String;
Interactive : Boolean) return String is
Interactive : Boolean;
Pushed : Boolean) return String is
Restart : Boolean;
Result : As.U.Asu_Us;
Tmp_Branch : As.U.Asu_Us;
Expand All @@ -53,7 +54,9 @@ package body Rebase_Mng is
& (if Reference_Branch /= "" then " from " & Reference_Branch else ""),
"on " & Target_Branch,
Warning => (if Restart then ""
else "This operation will alter the history")) );
elsif Pushed then "This operation will alter the pushed history"
else "This operation will alter the local history"),
Alert => Pushed) );
begin
Current_Branch := As.U.Tus (Git_If.Current_Branch);
-- Check if same rebase as previous and temporary branch still here
Expand Down
9 changes: 5 additions & 4 deletions usr/agite/branch.adb
Expand Up @@ -197,7 +197,8 @@ package body Branch is
Cancelled : constant String := Aski.Esc_S;
function Do_Rebase (Root : String;
Target_Branch, Reference_Branch: String;
Interactive : Boolean) return String;
Interactive : Boolean;
Pushed : Boolean) return String;
-- Reset memory of previous rebase
procedure Reset (Cherries : in Boolean);
end Rebase_Mng;
Expand Down Expand Up @@ -377,7 +378,7 @@ package body Branch is
Message2 := As.U.Tus ("to head of " & Sel_Name.Image);
Previous_Branch := Sel_Name;
Result := As.U.Tus (Rebase_Mng.Do_Rebase (Root.Image,
Sel_Name.Image, Ref_Name.Image, False));
Sel_Name.Image, Ref_Name.Image, False, True));
Init;
when Cherry_Pick =>
-- Reset memory of previous rebase
Expand Down Expand Up @@ -609,11 +610,11 @@ package body Branch is
end Handle;

-- Interactively rebase current branch from rev
function Reorg (Root, Rev : String) return Result_List is
function Reorg (Root, Rev : String; Pushed : Boolean) return Result_List is
Msg : As.U.Asu_Us;
use type As.U.Asu_Us;
begin
Msg := As.U.Tus (Rebase_Mng.Do_Rebase (Root, Rev, "", True));
Msg := As.U.Tus (Rebase_Mng.Do_Rebase (Root, Rev, "", True, Pushed));
if Msg.Is_Null then
return Ok;
elsif Msg = As.U.Tus (Rebase_Mng.Aborted) then
Expand Down
3 changes: 2 additions & 1 deletion usr/agite/branch.ads
Expand Up @@ -23,8 +23,9 @@ package Branch is
-- Return OK => Completed
-- Error => Error not recovered by user (e.g. user abort)
-- or Cancelled => Cancelled by user before starting, or nothing to do
-- Red warning if current commit has been pushed
type Result_List is (Ok, Error, Cancelled);
function Reorg (Root, Rev : String) return Result_List;
function Reorg (Root, Rev : String; Pushed : Boolean) return Result_List;

end Branch;

12 changes: 10 additions & 2 deletions usr/agite/confirm.adb
@@ -1,11 +1,12 @@
with Afpx;
with Utils.X, Afpx_Xref;
with Utils.X, Afpx_Xref, Con_Io;
-- Confirm: OK/Cancel or Yes/No, show (protected) of hide the list
function Confirm (Title, Action : String;
Msg1, Msg2, Msg_Below : String := "";
Warning : String := "";
Ok_Cancel : Boolean := True;
Show_List : Boolean := False) return Boolean is
Show_List : Boolean := False;
Alert : Boolean := True) return Boolean is
-- Afpx stuff
Get_Handle : Afpx.Get_Handle_Rec;
Ptg_Result : Afpx.Result_Rec;
Expand All @@ -25,6 +26,13 @@ begin
end if;
if Warning /= "" then
Utils.X.Center_Field ("WARNING: " & Warning, Afpx_Xref.Confirm.Warning);
if Alert then
Utils.X.Center_Field ("ALERT: " & Warning, Afpx_Xref.Confirm.Warning);
else
Utils.X.Center_Field ("WARNING: " & Warning, Afpx_Xref.Confirm.Warning);
Afpx.Set_Field_Colors (Afpx_Xref.Confirm.Warning,
Foreground => Con_Io.Color_Of ("Orange"));
end if;
end if;
-- Yes / No
if not Ok_Cancel then
Expand Down
59 changes: 46 additions & 13 deletions usr/agite/history.adb
Expand Up @@ -153,6 +153,9 @@ package body History is
All_Read : Boolean;
First_Rename : Ll_Natural;

-- The current item has been pushed
Pushed : Boolean;

-- Get the Hash of an entry
-- No_Hash if list is empty
-- Current Afpx position if Position is 0
Expand Down Expand Up @@ -340,7 +343,7 @@ package body History is
Result := Branches.Cancelled;
else
-- Reorg success or failure
Result := Branches.Reorg (Root, Hash.Image);
Result := Branches.Reorg (Root, Hash.Image, Pushed);
end if;
if Result = Branches.Cancelled then
-- Cancel => stay in Branch
Expand Down Expand Up @@ -374,7 +377,8 @@ package body History is
else
Str := As.U.Tus (Str_Util.Strip (Image1 (Log.Date)
& " " & Image2 (Log)));
Res := Reset (Root, Hash.Image, Comment => Str.Image);
Res := Reset (Root, Hash.Image, Comment => Str.Image,
Pushed => Pushed);
end if;
if Res then
return True;
Expand Down Expand Up @@ -512,6 +516,29 @@ package body History is
-- Index of remote head (0 if unknown)
Remote_Head_Index : Afpx.Line_List_Mng.Ll_Natural;

-- Update Push and ink versus remote head
procedure Update_Pushed (Index : in Afpx.Line_List_Mng.Ll_Natural) is
use type Afpx.Line_List_Mng.Ll_Natural;
begin
if Remote_Head_Index = 0 then
Pushed := True;
elsif Index > Remote_Head_Index then
Pushed := True;
else
Pushed := False;
end if;
if not Afpx.Get_Field_Protection (Afpx_Xref.History.Reorg)
and then Pushed then
Afpx.Set_Field_Colors (Afpx_Xref.History.Reorg,
Con_Io.Color_Of ("Red"));
end if;
if not Afpx.Get_Field_Protection (Afpx_Xref.History.Reset)
and then Pushed then
Afpx.Set_Field_Colors (Afpx_Xref.History.Reset,
Con_Io.Color_Of ("Red"));
end if;
end Update_Pushed;

-- Normalize Afpx list index
function Normal is new Normalization.Normal_Mod
(Afpx.Line_List_Mng.Ll_Natural);
Expand Down Expand Up @@ -571,16 +598,7 @@ package body History is
(not On_Root and then Right_Set)
or else Empty);
-- Set in Red the Reorg et Reset if current ref is below remote head
if not Afpx.Get_Field_Protection (Afpx_Xref.History.Reorg)
and then Remote_Head_Index /= 0 and then Left > Remote_Head_Index then
Afpx.Set_Field_Colors (Afpx_Xref.History.Reorg,
Con_Io.Color_Of ("Red"));
end if;
if not Afpx.Get_Field_Protection (Afpx_Xref.History.Reset)
and then Remote_Head_Index /= 0 and then Left > Remote_Head_Index then
Afpx.Set_Field_Colors (Afpx_Xref.History.Reset,
Con_Io.Color_Of ("Red"));
end if;
Update_Pushed (Left);
-- Show renamed file name if different
if Is_File then
if First_Rename /= 0
Expand Down Expand Up @@ -727,9 +745,14 @@ package body History is
-- Get history list with default length
Reread (False);

-- Set remote head
Remote_Head_Index := 0;
if Do_Remote_Head then
Remote_Head_Index := Logs.Get_Position;
end if;

-- Set current entry to the provided Hash
Log.Hash := Git_If.No_Hash;
Remote_Head_Index := 0;
Init_Indicator := Default_Init_Indicator;
Found := False;
if Hash /= Git_If.No_Hash then
Expand All @@ -741,6 +764,16 @@ package body History is
Init_Indicator := '?';
end if;
end if;
if not Found and then not Logs.Is_Empty then
Logs.Rewind;
end if;

-- Adjust Alert/warning
if not Logs.Is_Empty then
Update_Pushed (Logs.Get_Position);
else
Update_Pushed (1);
end if;

-- Encode history
Init_List (Logs);
Expand Down
18 changes: 14 additions & 4 deletions usr/agite/reset.adb
@@ -1,11 +1,12 @@
with Afpx;
with Utils.X, Afpx_Xref, Git_If;
with Utils.X, Afpx_Xref, Git_If, Con_Io;
-- Reset (soft/mixed/hard) or clean
function Reset (Root : String;
Ref : String;
Only_Hard : Boolean := False;
Allow_Clean : Boolean := False;
Comment : String := "") return Boolean is
Comment : String := "";
Pushed : in Boolean := True) return Boolean is
-- Afpx stuff
Get_Handle : Afpx.Get_Handle_Rec;
Ptg_Result : Afpx.Result_Rec;
Expand All @@ -28,8 +29,17 @@ begin
-- Comment of target commit
Utils.X.Encode_Field (Comment, Afpx_Xref.Reset.Comment);
end if;
Utils.X.Center_Field ("WARNING: This operation will alter the history",
Afpx_Xref.Reset.Warning);
if Pushed then
Utils.X.Center_Field (
"ALERT: This operation will alter the pushed history",
Afpx_Xref.Reset.Warning);
else
Afpx.Set_Field_Colors (Afpx_Xref.Reset.Warning,
Foreground => Con_Io.Color_Of ("Orange"));
Utils.X.Center_Field (
"WARNING: This operation will alter the local history",
Afpx_Xref.Reset.Warning);
end if;
else
-- No ref => Hard / Soft / Mixed reset to head or clean
Utils.X.Center_Field ("HEAD", Afpx_Xref.Reset.Title);
Expand Down

0 comments on commit 3d3a548

Please sign in to comment.