gix_refspec/instruction.rs
1use bstr::BStr;
2
3use crate::{Instruction, parse::Operation};
4
5impl Instruction<'_> {
6 /// Derive the mode of operation from this instruction.
7 pub fn operation(&self) -> Operation {
8 match self {
9 Instruction::Push(_) => Operation::Push,
10 Instruction::Fetch(_) => Operation::Fetch,
11 }
12 }
13}
14
15/// Sources are local ref names, ref patterns, or revision expressions unless specified otherwise.
16/// A non-pattern source with an explicit destination is kept without syntax validation, like Git.
17/// Destinations are partial or full ref names on the remote side.
18#[derive(PartialOrd, Ord, PartialEq, Eq, Copy, Clone, Hash, Debug)]
19pub enum Push<'a> {
20 /// Push all local branches to the matching destination on the remote, which has to exist to be updated.
21 AllMatchingBranches {
22 /// If true, allow non-fast-forward updates of the matched destination branch.
23 allow_non_fast_forward: bool,
24 },
25 /// Delete the destination ref.
26 Delete {
27 /// The reference to delete on the remote.
28 ref_or_pattern: &'a BStr,
29 },
30 /// Push the object or objects named by `src` to `dst`.
31 Matching {
32 /// The source expression to push. Non-pattern expressions with an explicit destination are not syntax-checked.
33 /// Ref patterns contain exactly one `*`, such as `refs/heads/*`.
34 src: &'a BStr,
35 /// The ref to update with the object from `src`. If `src` is a pattern, this is a pattern too.
36 /// Examples are refnames like `HEAD` or `refs/heads/main`, or patterns like `refs/heads/*`.
37 dst: &'a BStr,
38 /// If true, allow non-fast-forward updates of `dst`.
39 allow_non_fast_forward: bool,
40 },
41 /// Exclude a single ref.
42 Exclude {
43 /// A full or partial ref name to exclude, or a pattern containing a single `*`.
44 /// Partial names are matched literally; rev-specs and object hashes are not supported.
45 src: &'a BStr,
46 },
47}
48
49/// Sources are remote ref names or fully spelled object IDs unless specified otherwise.
50///
51/// Destinations are partial or full ref names on the local side.
52#[derive(PartialOrd, Ord, PartialEq, Eq, Copy, Clone, Hash, Debug)]
53pub enum Fetch<'a> {
54 /// Fetch a ref or refs, without updating local branches.
55 Only {
56 /// The partial or full ref name to fetch on the remote side or the full object hex-name, without updating the local side.
57 /// This cannot be a ref pattern, as a positive fetch pattern requires a patterned destination.
58 src: &'a BStr,
59 },
60 /// Exclude a single ref.
61 Exclude {
62 /// A partial or full ref name to exclude on the remote, or a pattern containing a single `*`.
63 /// Partial names are matched literally; object IDs are not supported.
64 src: &'a BStr,
65 },
66 /// Fetch from `src` and update the corresponding destination branches in `dst` accordingly.
67 AndUpdate {
68 /// The ref name to fetch on the remote side, or a pattern with a single `*` to match against, or the full object hex-name.
69 src: &'a BStr,
70 /// The local destination to update with what was fetched, or a pattern whose single `*` will be replaced with the matching portion
71 /// of the `*` from `src`.
72 dst: &'a BStr,
73 /// If true, allow non-fast-forward updates of `dest`.
74 allow_non_fast_forward: bool,
75 },
76}