|
| 1 | +use but_settings::AppSettings; |
| 2 | +use gitbutler_command_context::CommandContext; |
| 3 | +use gitbutler_project::Project; |
| 4 | + |
| 5 | +use crate::{id::CliId, rub::parse_sources}; |
| 6 | + |
| 7 | +/// Amends changes into the appropriate commits where they belong. |
| 8 | +/// |
| 9 | +/// The semantic for finding "the appropriate commit" is as follows |
| 10 | +/// - Changes are amended into the topmost commit of the leftmost (first) lane (branch) |
| 11 | +/// - If a change is assigned to a particular lane (branch), it will be amended into a commit there |
| 12 | +/// - If there are no commits in this branch, a new commit is created |
| 13 | +/// - If a change has a dependency to a particular commit, it will be amended into that particular commit |
| 14 | +/// |
| 15 | +/// Optionally an identifier to an Uncommitted File or a Branch (stack) may be provided. |
| 16 | +/// |
| 17 | +/// If an Uncommitted File id is provided, absorb will be peformed for just that file |
| 18 | +/// If a Branch (stack) id is provided, absorb will be performed for all changes assigned to that stack |
| 19 | +/// If no source is provided, absorb is performed for all uncommitted changes |
| 20 | +pub(crate) fn handle(project: &Project, _json: bool, source: Option<&str>) -> anyhow::Result<()> { |
| 21 | + let ctx = &mut CommandContext::open(project, AppSettings::load_from_default_path_creating()?)?; |
| 22 | + let source: Option<CliId> = source |
| 23 | + .and_then(|s| parse_sources(ctx, s).ok()) |
| 24 | + .and_then(|s| { |
| 25 | + s.into_iter().find(|s| { |
| 26 | + matches!(s, CliId::UncommittedFile { .. }) || matches!(s, CliId::Branch { .. }) |
| 27 | + }) |
| 28 | + }); |
| 29 | + if let Some(source) = source { |
| 30 | + match source { |
| 31 | + CliId::UncommittedFile { |
| 32 | + path: _, |
| 33 | + assignment: _, |
| 34 | + } => { |
| 35 | + // Absorb this particular file |
| 36 | + } |
| 37 | + CliId::Branch { name: _ } => { |
| 38 | + // Absorb everything that is assigned to this lane |
| 39 | + } |
| 40 | + _ => { |
| 41 | + // Invalid source - error out |
| 42 | + } |
| 43 | + } |
| 44 | + } else { |
| 45 | + // Try to absorb everhting uncommitted |
| 46 | + } |
| 47 | + Ok(()) |
| 48 | +} |
0 commit comments