gix_refspec/instruction.rs
1use bstr::BStr;
2
3use crate::{parse::Operation, Instruction};
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/// Note that all sources can either be a ref-name, partial or full, or a rev-spec, unless specified otherwise, on the local side.
16/// Destinations can only be a partial or full ref names on the remote side.
17#[derive(PartialOrd, Ord, PartialEq, Eq, Copy, Clone, Hash, Debug)]
18pub enum Push<'a> {
19 /// Push all local branches to the matching destination on the remote, which has to exist to be updated.
20 AllMatchingBranches {
21 /// If true, allow non-fast-forward updates of the matched destination branch.
22 allow_non_fast_forward: bool,
23 },
24 /// Delete the destination ref or glob pattern, with only a single `*` allowed.
25 Delete {
26 /// The reference or pattern to delete on the remote.
27 ref_or_pattern: &'a BStr,
28 },
29 /// Push a single ref or refspec to a known destination ref.
30 Matching {
31 /// The source ref or refspec to push. If pattern, it contains a single `*`.
32 /// Examples are refnames like `HEAD` or `refs/heads/main`, or patterns like `refs/heads/*`.
33 src: &'a BStr,
34 /// The ref to update with the object from `src`. If `src` is a pattern, this is a pattern too.
35 /// Examples are refnames like `HEAD` or `refs/heads/main`, or patterns like `refs/heads/*`.
36 dst: &'a BStr,
37 /// If true, allow non-fast-forward updates of `dest`.
38 allow_non_fast_forward: bool,
39 },
40}
41
42/// Any source can either be a ref name (full or partial) or a fully spelled out hex-sha for an object, on the remote side.
43///
44/// Destinations can only be a partial or full ref-names on the local side.
45#[derive(PartialOrd, Ord, PartialEq, Eq, Copy, Clone, Hash, Debug)]
46pub enum Fetch<'a> {
47 /// Fetch a ref or refs, without updating local branches.
48 Only {
49 /// The partial or full ref name to fetch on the remote side or the full object hex-name, without updating the local side.
50 /// Note that this may not be a glob pattern, as those need to be matched by a destination which isn't present here.
51 src: &'a BStr,
52 },
53 /// Exclude a single ref.
54 Exclude {
55 /// A single partial or full ref name to exclude on the remote, or a pattern with a single `*`. It cannot be a spelled out object hash.
56 src: &'a BStr,
57 },
58 /// Fetch from `src` and update the corresponding destination branches in `dst` accordingly.
59 AndUpdate {
60 /// The ref name to fetch on the remote side, or a pattern with a single `*` to match against, or the full object hex-name.
61 src: &'a BStr,
62 /// The local destination to update with what was fetched, or a pattern whose single `*` will be replaced with the matching portion
63 /// of the `*` from `src`.
64 dst: &'a BStr,
65 /// If true, allow non-fast-forward updates of `dest`.
66 allow_non_fast_forward: bool,
67 },
68}