Debian Codegraph @

src/lib.rs

raw ◀ ▶
1 Debian patch touch this file
1 //! # libgit2 bindings for Rust
2 //!
3 //! This library contains bindings to the [libgit2][1] C library which is used
4 //! to manage git repositories. The library itself is a work in progress and is
5 //! likely lacking some bindings here and there, so be warned.
6 //!
7 //! [1]: https://libgit2.org/
8 //!
9 //! The git2-rs library strives to be as close to libgit2 as possible, but also
10 //! strives to make using libgit2 as safe as possible. All resource management
11 //! is automatic as well as adding strong types to all interfaces (including
12 //! `Result`).
13 //!
14 //! ## Creating a `Repository`
15 //!
16 //! The `Repository` is the source from which almost all other objects in git-rs
17 //! are spawned. A repository can be created through opening, initializing, or
18 //! cloning.
19 //!
20 //! ### Initializing a new repository
21 //!
22 //! The `init` method will create a new repository, assuming one does not
23 //! already exist.
24 //!
25 //! ```no_run
26 //! # #![allow(unstable)]
27 //! use git2::Repository;
28 //!
29 //! let repo = match Repository::init("/path/to/a/repo") {
30 //! Ok(repo) => repo,
31 //! Err(e) => panic!("failed to init: {}", e),
32 //! };
33 //! ```
34 //!
35 //! ### Opening an existing repository
36 //!
37 //! ```no_run
38 //! # #![allow(unstable)]
39 //! use git2::Repository;
40 //!
41 //! let repo = match Repository::open("/path/to/a/repo") {
42 //! Ok(repo) => repo,
43 //! Err(e) => panic!("failed to open: {}", e),
44 //! };
45 //! ```
46 //!
47 //! ### Cloning an existing repository
48 //!
49 //! ```no_run
50 //! # #![allow(unstable)]
51 //! use git2::Repository;
52 //!
53 //! let url = "https://github.com/alexcrichton/git2-rs";
54 //! let repo = match Repository::clone(url, "/path/to/a/repo") {
55 //! Ok(repo) => repo,
56 //! Err(e) => panic!("failed to clone: {}", e),
57 //! };
58 //! ```
59 //!
60 //! To clone using SSH, refer to [RepoBuilder](./build/struct.RepoBuilder.html).
61 //!
62 //! ## Working with a `Repository`
63 //!
64 //! All derivative objects, references, etc are attached to the lifetime of the
65 //! source `Repository`, to ensure that they do not outlive the repository
66 //! itself.
67
68 #![doc(html_root_url = "https://docs.rs/git2/0.21")]
69 #![allow(trivial_numeric_casts, trivial_casts)]
70 #![deny(missing_docs)]
71 #![warn(rust_2018_idioms)]
72 #![cfg_attr(test, deny(warnings))]
73
74 use bitflags::bitflags;
75 use libgit2_sys as raw;
76
77 use std::ffi::{CStr, CString};
78 use std::fmt;
79 use std::str;
80 use std::sync::Once;
81
82 pub use crate::apply::{ApplyLocation, ApplyOptions};
83 pub use crate::attr::AttrValue;
84 pub use crate::blame::{Blame, BlameHunk, BlameIter, BlameOptions};
85 pub use crate::blob::{Blob, BlobWriter};
86 pub use crate::branch::{Branch, Branches};
87 pub use crate::buf::Buf;
88 pub use crate::cherrypick::CherrypickOptions;
89 pub use crate::commit::{Commit, Parents};
90 pub use crate::config::{Config, ConfigEntries, ConfigEntry};
91 pub use crate::cred::Cred;
92 #[cfg(feature = "cred")]
93 pub use crate::cred::CredentialHelper;
94 pub use crate::describe::{Describe, DescribeFormatOptions, DescribeOptions};
95 pub use crate::diff::{Deltas, Diff, DiffDelta, DiffFile, DiffOptions};
96 pub use crate::diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind, DiffPatchidOptions};
97 pub use crate::diff::{DiffFindOptions, DiffHunk, DiffLine, DiffLineType, DiffStats};
98 pub use crate::email::{Email, EmailCreateOptions};
99 pub use crate::error::Error;
100 pub use crate::index::{
101 Index, IndexConflict, IndexConflicts, IndexEntries, IndexEntry, IndexMatchedPath,
102 };
103 pub use crate::indexer::{Indexer, IndexerProgress, Progress};
104 pub use crate::mailmap::Mailmap;
105 pub use crate::mempack::Mempack;
106 pub use crate::merge::{
107 merge_file, AnnotatedCommit, MergeFileInput, MergeFileOptions, MergeFileResult, MergeOptions,
108 };
109 pub use crate::message::{
110 message_prettify, message_trailers_bytes, message_trailers_strs, MessageTrailersBytes,
111 MessageTrailersBytesIterator, MessageTrailersStrs, MessageTrailersStrsIterator,
112 DEFAULT_COMMENT_CHAR,
113 };
114 pub use crate::note::{Note, Notes};
115 pub use crate::object::Object;
116 pub use crate::odb::{Odb, OdbObject, OdbPackwriter, OdbReader, OdbWriter};
117 pub use crate::oid::ObjectFormat;
118 pub use crate::oid::Oid;
119 pub use crate::packbuilder::{PackBuilder, PackBuilderStage};
120 pub use crate::patch::Patch;
121 pub use crate::pathspec::{Pathspec, PathspecFailedEntries, PathspecMatchList};
122 pub use crate::pathspec::{PathspecDiffEntries, PathspecEntries};
123 pub use crate::proxy_options::ProxyOptions;
124 pub use crate::push_update::PushUpdate;
125 pub use crate::rebase::{Rebase, RebaseOperation, RebaseOperationType, RebaseOptions};
126 pub use crate::refdb::Refdb;
127 pub use crate::reference::{Reference, ReferenceNames, References};
128 pub use crate::reflog::{Reflog, ReflogEntry, ReflogIter};
129 pub use crate::refspec::Refspec;
130 pub use crate::remote::{
131 FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead, RemoteRedirect,
132 };
133 pub use crate::remote_callbacks::{CertificateCheckStatus, Credentials, RemoteCallbacks};
134 pub use crate::remote_callbacks::{TransportMessage, UpdateTips};
135 pub use crate::repo::{Repository, RepositoryInitOptions};
136 pub use crate::revert::RevertOptions;
137 pub use crate::revspec::Revspec;
138 pub use crate::revwalk::Revwalk;
139 pub use crate::signature::Signature;
140 pub use crate::stash::{StashApplyOptions, StashApplyProgressCb, StashCb, StashSaveOptions};
141 pub use crate::status::{StatusEntry, StatusIter, StatusOptions, StatusShow, Statuses};
142 pub use crate::submodule::{Submodule, SubmoduleUpdateOptions};
143 pub use crate::tag::Tag;
144 pub use crate::time::{IndexTime, Time};
145 pub use crate::tracing::{trace_set, TraceLevel};
146 pub use crate::transaction::Transaction;
147 pub use crate::tree::{Tree, TreeEntry, TreeIter, TreeWalkMode, TreeWalkResult};
148 pub use crate::treebuilder::TreeBuilder;
149 pub use crate::util::{Binding, IntoCString};
150 pub use crate::version::Version;
151 pub use crate::worktree::{Worktree, WorktreeAddOptions, WorktreeLockStatus, WorktreePruneOptions};
152
153 // Create a convinience method on bitflag struct which checks the given flag
154 macro_rules! is_bit_set {
155 ($name:ident, $flag:expr) => {
156 #[doc = concat!("Check if the ", stringify!($flag), " is set.")]
157 pub fn $name(&self) -> bool {
158 self.intersects($flag)
159 }
160 };
161 }
162
163 /// An enumeration of possible errors that can happen when working with a git
164 /// repository.
165 // Note: We omit a few native error codes, as they are unlikely to be propagated
166 // to the library user. Currently:
167 //
168 // * GIT_EPASSTHROUGH
169 // * GIT_ITEROVER
170 // * GIT_RETRY
171 #[derive(PartialEq, Eq, Clone, Debug, Copy)]
172 pub enum ErrorCode {
173 /// Generic error
174 GenericError,
175 /// Requested object could not be found
176 NotFound,
177 /// Object exists preventing operation
178 Exists,
179 /// More than one object matches
180 Ambiguous,
181 /// Output buffer too short to hold data
182 BufSize,
183 /// User-generated error
184 User,
185 /// Operation not allowed on bare repository
186 BareRepo,
187 /// HEAD refers to branch with no commits
188 UnbornBranch,
189 /// Merge in progress prevented operation
190 Unmerged,
191 /// Reference was not fast-forwardable
192 NotFastForward,
193 /// Name/ref spec was not in a valid format
194 InvalidSpec,
195 /// Checkout conflicts prevented operation
196 Conflict,
197 /// Lock file prevented operation
198 Locked,
199 /// Reference value does not match expected
200 Modified,
201 /// Authentication error
202 Auth,
203 /// Server certificate is invalid
204 Certificate,
205 /// Patch/merge has already been applied
206 Applied,
207 /// The requested peel operation is not possible
208 Peel,
209 /// Unexpected EOF
210 Eof,
211 /// Invalid operation or input
212 Invalid,
213 /// Uncommitted changes in index prevented operation
214 Uncommitted,
215 /// Operation was not valid for a directory
216 Directory,
217 /// A merge conflict exists and cannot continue
218 MergeConflict,
219 /// Hashsum mismatch in object
220 HashsumMismatch,
221 /// Unsaved changes in the index would be overwritten
222 IndexDirty,
223 /// Patch application failed
224 ApplyFail,
225 /// The object is not owned by the current user
226 Owner,
227 /// Timeout
228 Timeout,
229 }
230
231 /// An enumeration of possible categories of things that can have
232 /// errors when working with a git repository.
233 #[derive(PartialEq, Eq, Clone, Debug, Copy)]
234 pub enum ErrorClass {
235 /// Uncategorized
236 None,
237 /// Out of memory or insufficient allocated space
238 NoMemory,
239 /// Syscall or standard system library error
240 Os,
241 /// Invalid input
242 Invalid,
243 /// Error resolving or manipulating a reference
244 Reference,
245 /// ZLib failure
246 Zlib,
247 /// Bad repository state
248 Repository,
249 /// Bad configuration
250 Config,
251 /// Regex failure
252 Regex,
253 /// Bad object
254 Odb,
255 /// Invalid index data
256 Index,
257 /// Error creating or obtaining an object
258 Object,
259 /// Network error
260 Net,
261 /// Error manipulating a tag
262 Tag,
263 /// Invalid value in tree
264 Tree,
265 /// Hashing or packing error
266 Indexer,
267 /// Error from SSL
268 Ssl,
269 /// Error involving submodules
270 Submodule,
271 /// Threading error
272 Thread,
273 /// Error manipulating a stash
274 Stash,
275 /// Checkout failure
276 Checkout,
277 /// Invalid FETCH_HEAD
278 FetchHead,
279 /// Merge failure
280 Merge,
281 /// SSH failure
282 Ssh,
283 /// Error manipulating filters
284 Filter,
285 /// Error reverting commit
286 Revert,
287 /// Error from a user callback
288 Callback,
289 /// Error cherry-picking commit
290 CherryPick,
291 /// Can't describe object
292 Describe,
293 /// Error during rebase
294 Rebase,
295 /// Filesystem-related error
296 Filesystem,
297 /// Invalid patch data
298 Patch,
299 /// Error involving worktrees
300 Worktree,
301 /// Hash library error or SHA-1 collision
302 Sha1,
303 /// HTTP error
304 Http,
305 }
306
307 /// A listing of the possible states that a repository can be in.
308 #[derive(PartialEq, Eq, Clone, Debug, Copy)]
309 pub enum RepositoryState {
310 /// No operation is currently in progress
311 Clean,
312 /// A merge is currently in progress
313 Merge,
314 /// A revert is currently in progress
315 Revert,
316 /// A revert of multiple commits is currently in progress
317 RevertSequence,
318 /// A cherry pick is currently in progress
319 CherryPick,
320 /// A cherry pick of multiple commits is currently in progress
321 CherryPickSequence,
322 /// A bisect is currently in progress
323 Bisect,
324 /// A rebase is currently in progress
325 Rebase,
326 /// An interactive rebase is currently in progress
327 RebaseInteractive,
328 /// A rebase with a merge conflict is currently in progress
329 RebaseMerge,
330 /// An apply operation is currently in progress
331 ApplyMailbox,
332 /// A rebase or apply operation is currently in progress
333 ApplyMailboxOrRebase,
334 }
335
336 /// An enumeration of the possible directions for a remote.
337 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
338 pub enum Direction {
339 /// Data will be fetched (read) from this remote.
340 Fetch,
341 /// Data will be pushed (written) to this remote.
342 Push,
343 }
344
345 /// An enumeration of the operations that can be performed for the `reset`
346 /// method on a `Repository`.
347 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
348 pub enum ResetType {
349 /// Move the head to the given commit.
350 Soft,
351 /// Soft plus reset the index to the commit.
352 Mixed,
353 /// Mixed plus changes in the working tree are discarded.
354 Hard,
355 }
356
357 /// An enumeration all possible kinds objects may have.
358 #[derive(PartialEq, Eq, Copy, Clone, Debug)]
359 pub enum ObjectType {
360 /// Any kind of git object
361 Any,
362 /// An object which corresponds to a git commit
363 Commit,
364 /// An object which corresponds to a git tree
365 Tree,
366 /// An object which corresponds to a git blob
367 Blob,
368 /// An object which corresponds to a git tag
369 Tag,
370 }
371
372 /// An enumeration of all possible kinds of references.
373 #[derive(PartialEq, Eq, Copy, Clone, Debug)]
374 pub enum ReferenceType {
375 /// A reference which points at an object id.
376 Direct,
377
378 /// A reference which points at another reference.
379 Symbolic,
380 }
381
382 /// An enumeration for the possible types of branches
383 #[derive(PartialEq, Eq, Debug, Copy, Clone)]
384 pub enum BranchType {
385 /// A local branch not on a remote.
386 Local,
387 /// A branch for a remote.
388 Remote,
389 }
390
391 /// An enumeration of the possible priority levels of a config file.
392 ///
393 /// The levels corresponding to the escalation logic (higher to lower) when
394 /// searching for config entries.
395 #[derive(PartialEq, Eq, Debug, Copy, Clone)]
396 pub enum ConfigLevel {
397 /// System-wide on Windows, for compatibility with portable git
398 ProgramData = 1,
399 /// System-wide configuration file, e.g. /etc/gitconfig
400 System,
401 /// XDG-compatible configuration file, e.g. ~/.config/git/config
402 XDG,
403 /// User-specific configuration, e.g. ~/.gitconfig
404 Global,
405 /// Repository specific config, e.g. $PWD/.git/config
406 Local,
407 /// Worktree specific configuration file, e.g. $GIT_DIR/config.worktree
408 Worktree,
409 /// Application specific configuration file
410 App,
411 /// Highest level available
412 Highest = -1,
413 }
414
415 /// Merge file favor options for `MergeOptions` instruct the file-level
416 /// merging functionality how to deal with conflicting regions of the files.
417 #[derive(PartialEq, Eq, Debug, Copy, Clone)]
418 pub enum FileFavor {
419 /// When a region of a file is changed in both branches, a conflict will be
420 /// recorded in the index so that git_checkout can produce a merge file with
421 /// conflict markers in the working directory. This is the default.
422 Normal,
423 /// When a region of a file is changed in both branches, the file created
424 /// in the index will contain the "ours" side of any conflicting region.
425 /// The index will not record a conflict.
426 Ours,
427 /// When a region of a file is changed in both branches, the file created
428 /// in the index will contain the "theirs" side of any conflicting region.
429 /// The index will not record a conflict.
430 Theirs,
431 /// When a region of a file is changed in both branches, the file created
432 /// in the index will contain each unique line from each side, which has
433 /// the result of combining both files. The index will not record a conflict.
434 Union,
435 }
436
437 bitflags! {
438 /// Orderings that may be specified for Revwalk iteration.
439 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
440 pub struct Sort: u32 {
441 /// Sort the repository contents in no particular ordering.
442 ///
443 /// This sorting is arbitrary, implementation-specific, and subject to
444 /// change at any time. This is the default sorting for new walkers.
445 const NONE = raw::GIT_SORT_NONE as u32;
446
447 /// Sort the repository contents in topological order (children before
448 /// parents).
449 ///
450 /// This sorting mode can be combined with time sorting.
451 const TOPOLOGICAL = raw::GIT_SORT_TOPOLOGICAL as u32;
452
453 /// Sort the repository contents by commit time.
454 ///
455 /// This sorting mode can be combined with topological sorting.
456 const TIME = raw::GIT_SORT_TIME as u32;
457
458 /// Iterate through the repository contents in reverse order.
459 ///
460 /// This sorting mode can be combined with any others.
461 const REVERSE = raw::GIT_SORT_REVERSE as u32;
462 }
463 }
464
465 impl Sort {
466 is_bit_set!(is_none, Sort::NONE);
467 is_bit_set!(is_topological, Sort::TOPOLOGICAL);
468 is_bit_set!(is_time, Sort::TIME);
469 is_bit_set!(is_reverse, Sort::REVERSE);
470 }
471
472 bitflags! {
473 /// Types of credentials that can be requested by a credential callback.
474 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
475 pub struct CredentialType: u32 {
476 #[allow(missing_docs)]
477 const USER_PASS_PLAINTEXT = raw::GIT_CREDTYPE_USERPASS_PLAINTEXT as u32;
478 #[allow(missing_docs)]
479 const SSH_KEY = raw::GIT_CREDTYPE_SSH_KEY as u32;
480 #[allow(missing_docs)]
481 const SSH_MEMORY = raw::GIT_CREDTYPE_SSH_MEMORY as u32;
482 #[allow(missing_docs)]
483 const SSH_CUSTOM = raw::GIT_CREDTYPE_SSH_CUSTOM as u32;
484 #[allow(missing_docs)]
485 const DEFAULT = raw::GIT_CREDTYPE_DEFAULT as u32;
486 #[allow(missing_docs)]
487 const SSH_INTERACTIVE = raw::GIT_CREDTYPE_SSH_INTERACTIVE as u32;
488 #[allow(missing_docs)]
489 const USERNAME = raw::GIT_CREDTYPE_USERNAME as u32;
490 }
491 }
492
493 impl CredentialType {
494 is_bit_set!(is_user_pass_plaintext, CredentialType::USER_PASS_PLAINTEXT);
495 is_bit_set!(is_ssh_key, CredentialType::SSH_KEY);
496 is_bit_set!(is_ssh_memory, CredentialType::SSH_MEMORY);
497 is_bit_set!(is_ssh_custom, CredentialType::SSH_CUSTOM);
498 is_bit_set!(is_default, CredentialType::DEFAULT);
499 is_bit_set!(is_ssh_interactive, CredentialType::SSH_INTERACTIVE);
500 is_bit_set!(is_username, CredentialType::USERNAME);
501 }
502
503 impl Default for CredentialType {
504 fn default() -> Self {
505 CredentialType::DEFAULT
506 }
507 }
508
509 bitflags! {
510 /// Flags for the `flags` field of an IndexEntry.
511 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
512 pub struct IndexEntryFlag: u16 {
513 /// Set when the `extended_flags` field is valid.
514 const EXTENDED = raw::GIT_INDEX_ENTRY_EXTENDED as u16;
515 /// "Assume valid" flag
516 const VALID = raw::GIT_INDEX_ENTRY_VALID as u16;
517 }
518 }
519
520 impl IndexEntryFlag {
521 is_bit_set!(is_extended, IndexEntryFlag::EXTENDED);
522 is_bit_set!(is_valid, IndexEntryFlag::VALID);
523 }
524
525 bitflags! {
526 /// Flags for the `extended_flags` field of an IndexEntry.
527 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
528 pub struct IndexEntryExtendedFlag: u16 {
529 /// An "intent to add" entry from "git add -N"
530 const INTENT_TO_ADD = raw::GIT_INDEX_ENTRY_INTENT_TO_ADD as u16;
531 /// Skip the associated worktree file, for sparse checkouts
532 const SKIP_WORKTREE = raw::GIT_INDEX_ENTRY_SKIP_WORKTREE as u16;
533
534 #[allow(missing_docs)]
535 const UPTODATE = raw::GIT_INDEX_ENTRY_UPTODATE as u16;
536 }
537 }
538
539 impl IndexEntryExtendedFlag {
540 is_bit_set!(is_intent_to_add, IndexEntryExtendedFlag::INTENT_TO_ADD);
541 is_bit_set!(is_skip_worktree, IndexEntryExtendedFlag::SKIP_WORKTREE);
542 is_bit_set!(is_up_to_date, IndexEntryExtendedFlag::UPTODATE);
543 }
544
545 bitflags! {
546 /// Flags for APIs that add files matching pathspec
547 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
548 pub struct IndexAddOption: u32 {
549 /// Adds files that are not ignored to the index
550 const DEFAULT = raw::GIT_INDEX_ADD_DEFAULT as u32;
551 /// Allows adding otherwise ignored files to the index
552 const FORCE = raw::GIT_INDEX_ADD_FORCE as u32;
553 #[allow(missing_docs)]
554 const DISABLE_PATHSPEC_MATCH =
555 raw::GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH as u32;
556 #[allow(missing_docs)]
557 const CHECK_PATHSPEC = raw::GIT_INDEX_ADD_CHECK_PATHSPEC as u32;
558 }
559 }
560
561 impl IndexAddOption {
562 is_bit_set!(is_default, IndexAddOption::DEFAULT);
563 is_bit_set!(is_force, IndexAddOption::FORCE);
564 is_bit_set!(
565 is_disable_pathspec_match,
566 IndexAddOption::DISABLE_PATHSPEC_MATCH
567 );
568 is_bit_set!(is_check_pathspec, IndexAddOption::CHECK_PATHSPEC);
569 }
570
571 impl Default for IndexAddOption {
572 fn default() -> Self {
573 IndexAddOption::DEFAULT
574 }
575 }
576
577 bitflags! {
578 /// Flags for `Repository::open_ext`
579 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
580 pub struct RepositoryOpenFlags: u32 {
581 /// Only open the specified path; don't walk upward searching.
582 const NO_SEARCH = raw::GIT_REPOSITORY_OPEN_NO_SEARCH as u32;
583 /// Search across filesystem boundaries.
584 const CROSS_FS = raw::GIT_REPOSITORY_OPEN_CROSS_FS as u32;
585 /// Force opening as bare repository, and defer loading its config.
586 const BARE = raw::GIT_REPOSITORY_OPEN_BARE as u32;
587 /// Don't try appending `/.git` to the specified repository path.
588 const NO_DOTGIT = raw::GIT_REPOSITORY_OPEN_NO_DOTGIT as u32;
589 /// Respect environment variables like `$GIT_DIR`.
590 const FROM_ENV = raw::GIT_REPOSITORY_OPEN_FROM_ENV as u32;
591 }
592 }
593
594 impl RepositoryOpenFlags {
595 is_bit_set!(is_no_search, RepositoryOpenFlags::NO_SEARCH);
596 is_bit_set!(is_cross_fs, RepositoryOpenFlags::CROSS_FS);
597 is_bit_set!(is_bare, RepositoryOpenFlags::BARE);
598 is_bit_set!(is_no_dotgit, RepositoryOpenFlags::NO_DOTGIT);
599 is_bit_set!(is_from_env, RepositoryOpenFlags::FROM_ENV);
600 }
601
602 bitflags! {
603 /// Flags for the return value of `Repository::revparse`
604 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
605 pub struct RevparseMode: u32 {
606 /// The spec targeted a single object
607 const SINGLE = raw::GIT_REVPARSE_SINGLE as u32;
608 /// The spec targeted a range of commits
609 const RANGE = raw::GIT_REVPARSE_RANGE as u32;
610 /// The spec used the `...` operator, which invokes special semantics.
611 const MERGE_BASE = raw::GIT_REVPARSE_MERGE_BASE as u32;
612 }
613 }
614
615 impl RevparseMode {
616 is_bit_set!(is_no_single, RevparseMode::SINGLE);
617 is_bit_set!(is_range, RevparseMode::RANGE);
618 is_bit_set!(is_merge_base, RevparseMode::MERGE_BASE);
619 }
620
621 bitflags! {
622 /// The results of `merge_analysis` indicating the merge opportunities.
623 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
624 pub struct MergeAnalysis: u32 {
625 /// No merge is possible.
626 const ANALYSIS_NONE = raw::GIT_MERGE_ANALYSIS_NONE as u32;
627 /// A "normal" merge; both HEAD and the given merge input have diverged
628 /// from their common ancestor. The divergent commits must be merged.
629 const ANALYSIS_NORMAL = raw::GIT_MERGE_ANALYSIS_NORMAL as u32;
630 /// All given merge inputs are reachable from HEAD, meaning the
631 /// repository is up-to-date and no merge needs to be performed.
632 const ANALYSIS_UP_TO_DATE = raw::GIT_MERGE_ANALYSIS_UP_TO_DATE as u32;
633 /// The given merge input is a fast-forward from HEAD and no merge
634 /// needs to be performed. Instead, the client can check out the
635 /// given merge input.
636 const ANALYSIS_FASTFORWARD = raw::GIT_MERGE_ANALYSIS_FASTFORWARD as u32;
637 /// The HEAD of the current repository is "unborn" and does not point to
638 /// a valid commit. No merge can be performed, but the caller may wish
639 /// to simply set HEAD to the target commit(s).
640 const ANALYSIS_UNBORN = raw::GIT_MERGE_ANALYSIS_UNBORN as u32;
641 }
642 }
643
644 impl MergeAnalysis {
645 is_bit_set!(is_none, MergeAnalysis::ANALYSIS_NONE);
646 is_bit_set!(is_normal, MergeAnalysis::ANALYSIS_NORMAL);
647 is_bit_set!(is_up_to_date, MergeAnalysis::ANALYSIS_UP_TO_DATE);
648 is_bit_set!(is_fast_forward, MergeAnalysis::ANALYSIS_FASTFORWARD);
649 is_bit_set!(is_unborn, MergeAnalysis::ANALYSIS_UNBORN);
650 }
651
652 bitflags! {
653 /// The user's stated preference for merges.
654 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
655 pub struct MergePreference: u32 {
656 /// No configuration was found that suggests a preferred behavior for
657 /// merge.
658 const NONE = raw::GIT_MERGE_PREFERENCE_NONE as u32;
659 /// There is a `merge.ff=false` configuration setting, suggesting that
660 /// the user does not want to allow a fast-forward merge.
661 const NO_FAST_FORWARD = raw::GIT_MERGE_PREFERENCE_NO_FASTFORWARD as u32;
662 /// There is a `merge.ff=only` configuration setting, suggesting that
663 /// the user only wants fast-forward merges.
664 const FASTFORWARD_ONLY = raw::GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY as u32;
665 }
666 }
667
668 impl MergePreference {
669 is_bit_set!(is_none, MergePreference::NONE);
670 is_bit_set!(is_no_fast_forward, MergePreference::NO_FAST_FORWARD);
671 is_bit_set!(is_fastforward_only, MergePreference::FASTFORWARD_ONLY);
672 }
673
674 bitflags! {
675 /// Flags controlling the behavior of ODB lookup operations
676 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
677 pub struct OdbLookupFlags: u32 {
678 /// Don't call `git_odb_refresh` if the lookup fails. Useful when doing
679 /// a batch of lookup operations for objects that may legitimately not
680 /// exist. When using this flag, you may wish to manually call
681 /// `git_odb_refresh` before processing a batch of objects.
682 const NO_REFRESH = raw::GIT_ODB_LOOKUP_NO_REFRESH as u32;
683 }
684 }
685
686 bitflags! {
687 /// How to handle reference updates.
688 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
689 pub struct RemoteUpdateFlags: u32 {
690 /// Write the fetch results to FETCH_HEAD.
691 const UPDATE_FETCHHEAD = raw::GIT_REMOTE_UPDATE_FETCHHEAD as u32;
692 /// Report unchanged tips in the update_tips callback.
693 const REPORT_UNCHANGED = raw::GIT_REMOTE_UPDATE_REPORT_UNCHANGED as u32;
694 }
695 }
696
697 #[cfg(test)]
698 #[macro_use]
699 mod test;
700 #[macro_use]
701 mod panic;
702 mod attr;
703 mod call;
704 mod util;
705
706 pub mod build;
707 pub mod cert;
708 pub mod oid_array;
709 pub mod opts;
710 pub mod string_array;
711 pub mod transport;
712
713 mod apply;
714 mod blame;
715 mod blob;
716 mod branch;
717 mod buf;
718 mod cherrypick;
719 mod commit;
720 mod config;
721 mod cred;
722 mod describe;
723 mod diff;
724 mod email;
725 mod error;
726 mod index;
727 mod indexer;
728 mod mailmap;
729 mod mempack;
730 mod merge;
731 mod message;
732 mod note;
733 mod object;
734 mod odb;
735 mod oid;
736 mod packbuilder;
737 mod patch;
738 mod pathspec;
739 mod proxy_options;
740 mod push_update;
741 mod rebase;
742 mod refdb;
743 mod reference;
744 mod reflog;
745 mod refspec;
746 mod remote;
747 mod remote_callbacks;
748 mod repo;
749 mod revert;
750 mod revspec;
751 mod revwalk;
752 mod signature;
753 mod stash;
754 mod status;
755 mod submodule;
756 mod tag;
757 mod tagforeach;
758 mod time;
759 mod tracing;
760 mod transaction;
761 mod tree;
762 mod treebuilder;
763 mod version;
764 mod worktree;
765
766 fn init() {
767 static INIT: Once = Once::new();
768
769 INIT.call_once(|| {
770 openssl_env_init();
771 });
772
773 raw::init();
774 }
775
776 #[cfg(all(
777 unix,
778 not(target_os = "macos"),
779 not(target_os = "ios"),
780 feature = "https"
781 ))]
782 fn openssl_env_init() {
783 // Currently, libgit2 leverages OpenSSL for SSL support when cloning
784 // repositories over HTTPS. This means that we're picking up an OpenSSL
785 // dependency on non-Windows platforms (where it has its own HTTPS
786 // subsystem). As a result, we need to link to OpenSSL.
787 //
788 // Now actually *linking* to OpenSSL isn't so hard. We just need to make
789 // sure to use pkg-config to discover any relevant system dependencies for
790 // differences between distributions like CentOS and Ubuntu. The actual
791 // trickiness comes about when we start *distributing* the resulting
792 // binaries. Currently Cargo is distributed in binary form as nightlies,
793 // which means we're distributing a binary with OpenSSL linked in.
794 //
795 // For historical reasons, the Linux nightly builder is running a CentOS
796 // distribution in order to have as much ABI compatibility with other
797 // distributions as possible. Sadly, however, this compatibility does not
798 // extend to OpenSSL. Currently OpenSSL has two major versions, 0.9 and 1.0,
799 // which are incompatible (many ABI differences). The CentOS builder we
800 // build on has version 1.0, as do most distributions today. Some still have
801 // 0.9, however. This means that if we are to distribute the binaries built
802 // by the CentOS machine, we would only be compatible with OpenSSL 1.0 and
803 // we would fail to run (a dynamic linker error at runtime) on systems with
804 // only 9.8 installed (hopefully).
805 //
806 // But wait, the plot thickens! Apparently CentOS has dubbed their OpenSSL
807 // library as `libssl.so.10`, notably the `10` is included at the end. On
808 // the other hand Ubuntu, for example, only distributes `libssl.so`. This
809 // means that the binaries created at CentOS are hard-wired to probe for a
810 // file called `libssl.so.10` at runtime (using the LD_LIBRARY_PATH), which
811 // will not be found on ubuntu. The conclusion of this is that binaries
812 // built on CentOS cannot be distributed to Ubuntu and run successfully.
813 //
814 // There are a number of sneaky things we could do, including, but not
815 // limited to:
816 //
817 // 1. Create a shim program which runs "just before" cargo runs. The
818 // responsibility of this shim program would be to locate `libssl.so`,
819 // whatever it's called, on the current system, make sure there's a
820 // symlink *somewhere* called `libssl.so.10`, and then set up
821 // LD_LIBRARY_PATH and run the actual cargo.
822 //
823 // This approach definitely seems unconventional, and is borderline
824 // overkill for this problem. It's also dubious if we can find a
825 // libssl.so reliably on the target system.
826 //
827 // 2. Somehow re-work the CentOS installation so that the linked-against
828 // library is called libssl.so instead of libssl.so.10
829 //
830 // The problem with this approach is that systems with 0.9 installed will
831 // start to silently fail, due to also having libraries called libssl.so
832 // (probably symlinked under a more appropriate version).
833 //
834 // 3. Compile Cargo against both OpenSSL 1.0 *and* OpenSSL 0.9, and
835 // distribute both. Also make sure that the linked-against name of the
836 // library is `libssl.so`. At runtime we determine which version is
837 // installed, and we then the appropriate binary.
838 //
839 // This approach clearly has drawbacks in terms of infrastructure and
840 // feasibility.
841 //
842 // 4. Build a nightly of Cargo for each distribution we'd like to support.
843 // You would then pick the appropriate Cargo nightly to install locally.
844 //
845 // So, with all this in mind, the decision was made to *statically* link
846 // OpenSSL. This solves any problem of relying on a downstream OpenSSL
847 // version being available. This does, however, open a can of worms related
848 // to security issues. It's generally a good idea to dynamically link
849 // OpenSSL as you'll get security updates over time without having to do
850 // anything (the system administrator will update the local openssl
851 // package). By statically linking, we're forfeiting this feature.
852 //
853 // The conclusion was made it is likely appropriate for the Cargo nightlies
854 // to statically link OpenSSL, but highly encourage distributions and
855 // packagers of Cargo to dynamically link OpenSSL. Packagers are targeting
856 // one system and are distributing to only that system, so none of the
857 // problems mentioned above would arise.
858 //
859 // In order to support this, a new package was made: openssl-static-sys.
860 // This package currently performs a fairly simple task:
861 //
862 // 1. Run pkg-config to discover where openssl is installed.
863 // 2. If openssl is installed in a nonstandard location, *and* static copies
864 // of the libraries are available, copy them to $OUT_DIR.
865 //
866 // This library will bring in libssl.a and libcrypto.a into the local build,
867 // allowing them to be picked up by this crate. This allows us to configure
868 // our own buildbots to have pkg-config point to these local pre-built
869 // copies of a static OpenSSL (with very few dependencies) while allowing
870 // most other builds of Cargo to naturally dynamically link OpenSSL.
871 //
872 // So in summary, if you're with me so far, we've statically linked OpenSSL
873 // to the Cargo binary (or any binary, for that matter) and we're ready to
874 // distribute it to *all* linux distributions. Remember that our original
875 // intent for openssl was for HTTPS support, which implies that we need some
876 // for of CA certificate store to validate certificates. This is normally
877 // installed in a standard system location.
878 //
879 // Unfortunately, as one might imagine, OpenSSL is configured for where this
880 // standard location is at *build time*, but it often varies widely
881 // per-system. Consequently, it was discovered that OpenSSL will respect the
882 // SSL_CERT_FILE and SSL_CERT_DIR environment variables in order to assist
883 // in discovering the location of this file (hurray!).
884 //
885 // So, finally getting to the point, this function solely exists to support
886 // our static builds of OpenSSL by probing for the "standard system
887 // location" of certificates and setting relevant environment variable to
888 // point to them.
889 //
890 // Ah, and as a final note, this is only a problem on Linux, not on OS X. On
891 // OS X the OpenSSL binaries are stable enough that we can just rely on
892 // dynamic linkage (plus they have some weird modifications to OpenSSL which
893 // means we wouldn't want to link statically).
894 #[allow(deprecated)] // FIXME: use init_openssl_env_vars instead
•895 unsafe {
896 openssl_probe::try_init_openssl_env_vars();
897 }
898 }
899
900 #[cfg(any(
901 windows,
902 target_os = "macos",
903 target_os = "ios",
904 not(feature = "https")
905 ))]
906 fn openssl_env_init() {}
907
908 unsafe fn opt_bytes<'a, T>(_anchor: &'a T, c: *const libc::c_char) -> Option<&'a [u8]> {
909 if c.is_null() {
910 None
911 } else {
912 Some(CStr::from_ptr(c).to_bytes())
913 }
914 }
915
916 fn opt_cstr<T: IntoCString>(o: Option<T>) -> Result<Option<CString>, Error> {
917 match o {
918 Some(s) => s.into_c_string().map(Some),
919 None => Ok(None),
920 }
921 }
922
923 impl ObjectType {
924 /// Convert an object type to its string representation.
925 pub fn str(&self) -> &'static str {
926 unsafe {
927 let ptr = call!(raw::git_object_type2string(*self)) as *const _;
928 let data = CStr::from_ptr(ptr).to_bytes();
929 str::from_utf8(data).unwrap()
930 }
931 }
932
933 /// Determine if the given git_object_t is a valid loose object type.
934 pub fn is_loose(&self) -> bool {
935 unsafe { call!(raw::git_object_typeisloose(*self)) == 1 }
936 }
937
938 /// Convert a raw git_object_t to an ObjectType
939 pub fn from_raw(raw: raw::git_object_t) -> Option<ObjectType> {
940 match raw {
941 raw::GIT_OBJECT_ANY => Some(ObjectType::Any),
942 raw::GIT_OBJECT_COMMIT => Some(ObjectType::Commit),
943 raw::GIT_OBJECT_TREE => Some(ObjectType::Tree),
944 raw::GIT_OBJECT_BLOB => Some(ObjectType::Blob),
945 raw::GIT_OBJECT_TAG => Some(ObjectType::Tag),
946 _ => None,
947 }
948 }
949
950 /// Convert this kind into its raw representation
951 pub fn raw(&self) -> raw::git_object_t {
952 call::convert(self)
953 }
954
955 /// Convert a string object type representation to its object type.
956 pub fn from_str(s: &str) -> Option<ObjectType> {
957 let raw = unsafe { call!(raw::git_object_string2type(CString::new(s).unwrap())) };
958 ObjectType::from_raw(raw)
959 }
960 }
961
962 impl fmt::Display for ObjectType {
963 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
964 self.str().fmt(f)
965 }
966 }
967
968 impl ReferenceType {
969 /// Convert an object type to its string representation.
970 pub fn str(&self) -> &'static str {
971 match self {
972 ReferenceType::Direct => "direct",
973 ReferenceType::Symbolic => "symbolic",
974 }
975 }
976
977 /// Convert a raw git_reference_t to a ReferenceType.
978 pub fn from_raw(raw: raw::git_reference_t) -> Option<ReferenceType> {
979 match raw {
980 raw::GIT_REFERENCE_DIRECT => Some(ReferenceType::Direct),
981 raw::GIT_REFERENCE_SYMBOLIC => Some(ReferenceType::Symbolic),
982 _ => None,
983 }
984 }
985 }
986
987 impl fmt::Display for ReferenceType {
988 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
989 self.str().fmt(f)
990 }
991 }
992
993 impl ConfigLevel {
994 /// Converts a raw configuration level to a ConfigLevel
995 pub fn from_raw(raw: raw::git_config_level_t) -> ConfigLevel {
996 match raw {
997 raw::GIT_CONFIG_LEVEL_PROGRAMDATA => ConfigLevel::ProgramData,
998 raw::GIT_CONFIG_LEVEL_SYSTEM => ConfigLevel::System,
999 raw::GIT_CONFIG_LEVEL_XDG => ConfigLevel::XDG,
1000 raw::GIT_CONFIG_LEVEL_GLOBAL => ConfigLevel::Global,
1001 raw::GIT_CONFIG_LEVEL_LOCAL => ConfigLevel::Local,
1002 raw::GIT_CONFIG_LEVEL_WORKTREE => ConfigLevel::Worktree,
1003 raw::GIT_CONFIG_LEVEL_APP => ConfigLevel::App,
1004 raw::GIT_CONFIG_HIGHEST_LEVEL => ConfigLevel::Highest,
1005 n => panic!("unknown config level: {}", n),
1006 }
1007 }
1008 }
1009
1010 impl SubmoduleIgnore {
1011 /// Converts a [`raw::git_submodule_ignore_t`] to a [`SubmoduleIgnore`]
1012 pub fn from_raw(raw: raw::git_submodule_ignore_t) -> Self {
1013 match raw {
1014 raw::GIT_SUBMODULE_IGNORE_UNSPECIFIED => SubmoduleIgnore::Unspecified,
1015 raw::GIT_SUBMODULE_IGNORE_NONE => SubmoduleIgnore::None,
1016 raw::GIT_SUBMODULE_IGNORE_UNTRACKED => SubmoduleIgnore::Untracked,
1017 raw::GIT_SUBMODULE_IGNORE_DIRTY => SubmoduleIgnore::Dirty,
1018 raw::GIT_SUBMODULE_IGNORE_ALL => SubmoduleIgnore::All,
1019 n => panic!("unknown submodule ignore rule: {}", n),
1020 }
1021 }
1022 }
1023
1024 impl SubmoduleUpdate {
1025 /// Converts a [`raw::git_submodule_update_t`] to a [`SubmoduleUpdate`]
1026 pub fn from_raw(raw: raw::git_submodule_update_t) -> Self {
1027 match raw {
1028 raw::GIT_SUBMODULE_UPDATE_CHECKOUT => SubmoduleUpdate::Checkout,
1029 raw::GIT_SUBMODULE_UPDATE_REBASE => SubmoduleUpdate::Rebase,
1030 raw::GIT_SUBMODULE_UPDATE_MERGE => SubmoduleUpdate::Merge,
1031 raw::GIT_SUBMODULE_UPDATE_NONE => SubmoduleUpdate::None,
1032 raw::GIT_SUBMODULE_UPDATE_DEFAULT => SubmoduleUpdate::Default,
1033 n => panic!("unknown submodule update strategy: {}", n),
1034 }
1035 }
1036 }
1037
1038 bitflags! {
1039 /// Status flags for a single file
1040 ///
1041 /// A combination of these values will be returned to indicate the status of
1042 /// a file. Status compares the working directory, the index, and the
1043 /// current HEAD of the repository. The `STATUS_INDEX_*` set of flags
1044 /// represents the status of file in the index relative to the HEAD, and the
1045 /// `STATUS_WT_*` set of flags represent the status of the file in the
1046 /// working directory relative to the index.
1047 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1048 pub struct Status: u32 {
1049 #[allow(missing_docs)]
1050 const CURRENT = raw::GIT_STATUS_CURRENT as u32;
1051
1052 #[allow(missing_docs)]
1053 const INDEX_NEW = raw::GIT_STATUS_INDEX_NEW as u32;
1054 #[allow(missing_docs)]
1055 const INDEX_MODIFIED = raw::GIT_STATUS_INDEX_MODIFIED as u32;
1056 #[allow(missing_docs)]
1057 const INDEX_DELETED = raw::GIT_STATUS_INDEX_DELETED as u32;
1058 #[allow(missing_docs)]
1059 const INDEX_RENAMED = raw::GIT_STATUS_INDEX_RENAMED as u32;
1060 #[allow(missing_docs)]
1061 const INDEX_TYPECHANGE = raw::GIT_STATUS_INDEX_TYPECHANGE as u32;
1062
1063 #[allow(missing_docs)]
1064 const WT_NEW = raw::GIT_STATUS_WT_NEW as u32;
1065 #[allow(missing_docs)]
1066 const WT_MODIFIED = raw::GIT_STATUS_WT_MODIFIED as u32;
1067 #[allow(missing_docs)]
1068 const WT_DELETED = raw::GIT_STATUS_WT_DELETED as u32;
1069 #[allow(missing_docs)]
1070 const WT_TYPECHANGE = raw::GIT_STATUS_WT_TYPECHANGE as u32;
1071 #[allow(missing_docs)]
1072 const WT_RENAMED = raw::GIT_STATUS_WT_RENAMED as u32;
1073 #[allow(missing_docs)]
1074 const WT_UNREADABLE = raw::GIT_STATUS_WT_UNREADABLE as u32;
1075
1076 #[allow(missing_docs)]
1077 const IGNORED = raw::GIT_STATUS_IGNORED as u32;
1078 #[allow(missing_docs)]
1079 const CONFLICTED = raw::GIT_STATUS_CONFLICTED as u32;
1080 }
1081 }
1082
1083 impl Status {
1084 is_bit_set!(is_index_new, Status::INDEX_NEW);
1085 is_bit_set!(is_index_modified, Status::INDEX_MODIFIED);
1086 is_bit_set!(is_index_deleted, Status::INDEX_DELETED);
1087 is_bit_set!(is_index_renamed, Status::INDEX_RENAMED);
1088 is_bit_set!(is_index_typechange, Status::INDEX_TYPECHANGE);
1089 is_bit_set!(is_wt_new, Status::WT_NEW);
1090 is_bit_set!(is_wt_modified, Status::WT_MODIFIED);
1091 is_bit_set!(is_wt_deleted, Status::WT_DELETED);
1092 is_bit_set!(is_wt_typechange, Status::WT_TYPECHANGE);
1093 is_bit_set!(is_wt_renamed, Status::WT_RENAMED);
1094 is_bit_set!(is_ignored, Status::IGNORED);
1095 is_bit_set!(is_conflicted, Status::CONFLICTED);
1096 }
1097
1098 bitflags! {
1099 /// Mode options for RepositoryInitOptions
1100 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1101 pub struct RepositoryInitMode: u32 {
1102 /// Use permissions configured by umask - the default
1103 const SHARED_UMASK = raw::GIT_REPOSITORY_INIT_SHARED_UMASK as u32;
1104 /// Use `--shared=group` behavior, chmod'ing the new repo to be
1105 /// group writable and \"g+sx\" for sticky group assignment
1106 const SHARED_GROUP = raw::GIT_REPOSITORY_INIT_SHARED_GROUP as u32;
1107 /// Use `--shared=all` behavior, adding world readability.
1108 const SHARED_ALL = raw::GIT_REPOSITORY_INIT_SHARED_ALL as u32;
1109 }
1110 }
1111
1112 impl RepositoryInitMode {
1113 is_bit_set!(is_shared_umask, RepositoryInitMode::SHARED_UMASK);
1114 is_bit_set!(is_shared_group, RepositoryInitMode::SHARED_GROUP);
1115 is_bit_set!(is_shared_all, RepositoryInitMode::SHARED_ALL);
1116 }
1117
1118 /// What type of change is described by a `DiffDelta`?
1119 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1120 pub enum Delta {
1121 /// No changes
1122 Unmodified,
1123 /// Entry does not exist in old version
1124 Added,
1125 /// Entry does not exist in new version
1126 Deleted,
1127 /// Entry content changed between old and new
1128 Modified,
1129 /// Entry was renamed between old and new
1130 Renamed,
1131 /// Entry was copied from another old entry
1132 Copied,
1133 /// Entry is ignored item in workdir
1134 Ignored,
1135 /// Entry is untracked item in workdir
1136 Untracked,
1137 /// Type of entry changed between old and new
1138 Typechange,
1139 /// Entry is unreadable
1140 Unreadable,
1141 /// Entry in the index is conflicted
1142 Conflicted,
1143 }
1144
1145 /// Valid modes for index and tree entries.
1146 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1147 pub enum FileMode {
1148 /// Unreadable
1149 Unreadable,
1150 /// Tree
1151 Tree,
1152 /// Blob
1153 Blob,
1154 /// Group writable blob. Obsolete mode kept for compatibility reasons
1155 BlobGroupWritable,
1156 /// Blob executable
1157 BlobExecutable,
1158 /// Link
1159 Link,
1160 /// Commit
1161 Commit,
1162 }
1163
1164 impl From<FileMode> for i32 {
1165 fn from(mode: FileMode) -> i32 {
1166 match mode {
1167 FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as i32,
1168 FileMode::Tree => raw::GIT_FILEMODE_TREE as i32,
1169 FileMode::Blob => raw::GIT_FILEMODE_BLOB as i32,
1170 FileMode::BlobGroupWritable => raw::GIT_FILEMODE_BLOB_GROUP_WRITABLE as i32,
1171 FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as i32,
1172 FileMode::Link => raw::GIT_FILEMODE_LINK as i32,
1173 FileMode::Commit => raw::GIT_FILEMODE_COMMIT as i32,
1174 }
1175 }
1176 }
1177
1178 impl From<FileMode> for u32 {
1179 fn from(mode: FileMode) -> u32 {
1180 match mode {
1181 FileMode::Unreadable => raw::GIT_FILEMODE_UNREADABLE as u32,
1182 FileMode::Tree => raw::GIT_FILEMODE_TREE as u32,
1183 FileMode::Blob => raw::GIT_FILEMODE_BLOB as u32,
1184 FileMode::BlobGroupWritable => raw::GIT_FILEMODE_BLOB_GROUP_WRITABLE as u32,
1185 FileMode::BlobExecutable => raw::GIT_FILEMODE_BLOB_EXECUTABLE as u32,
1186 FileMode::Link => raw::GIT_FILEMODE_LINK as u32,
1187 FileMode::Commit => raw::GIT_FILEMODE_COMMIT as u32,
1188 }
1189 }
1190 }
1191
1192 bitflags! {
1193 /// Return codes for submodule status.
1194 ///
1195 /// A combination of these flags will be returned to describe the status of a
1196 /// submodule. Depending on the "ignore" property of the submodule, some of
1197 /// the flags may never be returned because they indicate changes that are
1198 /// supposed to be ignored.
1199 ///
1200 /// Submodule info is contained in 4 places: the HEAD tree, the index, config
1201 /// files (both .git/config and .gitmodules), and the working directory. Any
1202 /// or all of those places might be missing information about the submodule
1203 /// depending on what state the repo is in. We consider all four places to
1204 /// build the combination of status flags.
1205 ///
1206 /// There are four values that are not really status, but give basic info
1207 /// about what sources of submodule data are available. These will be
1208 /// returned even if ignore is set to "ALL".
1209 ///
1210 /// * IN_HEAD - superproject head contains submodule
1211 /// * IN_INDEX - superproject index contains submodule
1212 /// * IN_CONFIG - superproject gitmodules has submodule
1213 /// * IN_WD - superproject workdir has submodule
1214 ///
1215 /// The following values will be returned so long as ignore is not "ALL".
1216 ///
1217 /// * INDEX_ADDED - in index, not in head
1218 /// * INDEX_DELETED - in head, not in index
1219 /// * INDEX_MODIFIED - index and head don't match
1220 /// * WD_UNINITIALIZED - workdir contains empty directory
1221 /// * WD_ADDED - in workdir, not index
1222 /// * WD_DELETED - in index, not workdir
1223 /// * WD_MODIFIED - index and workdir head don't match
1224 ///
1225 /// The following can only be returned if ignore is "NONE" or "UNTRACKED".
1226 ///
1227 /// * WD_INDEX_MODIFIED - submodule workdir index is dirty
1228 /// * WD_WD_MODIFIED - submodule workdir has modified files
1229 ///
1230 /// Lastly, the following will only be returned for ignore "NONE".
1231 ///
1232 /// * WD_UNTRACKED - workdir contains untracked files
1233 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1234 pub struct SubmoduleStatus: u32 {
1235 #[allow(missing_docs)]
1236 const IN_HEAD = raw::GIT_SUBMODULE_STATUS_IN_HEAD as u32;
1237 #[allow(missing_docs)]
1238 const IN_INDEX = raw::GIT_SUBMODULE_STATUS_IN_INDEX as u32;
1239 #[allow(missing_docs)]
1240 const IN_CONFIG = raw::GIT_SUBMODULE_STATUS_IN_CONFIG as u32;
1241 #[allow(missing_docs)]
1242 const IN_WD = raw::GIT_SUBMODULE_STATUS_IN_WD as u32;
1243 #[allow(missing_docs)]
1244 const INDEX_ADDED = raw::GIT_SUBMODULE_STATUS_INDEX_ADDED as u32;
1245 #[allow(missing_docs)]
1246 const INDEX_DELETED = raw::GIT_SUBMODULE_STATUS_INDEX_DELETED as u32;
1247 #[allow(missing_docs)]
1248 const INDEX_MODIFIED = raw::GIT_SUBMODULE_STATUS_INDEX_MODIFIED as u32;
1249 #[allow(missing_docs)]
1250 const WD_UNINITIALIZED =
1251 raw::GIT_SUBMODULE_STATUS_WD_UNINITIALIZED as u32;
1252 #[allow(missing_docs)]
1253 const WD_ADDED = raw::GIT_SUBMODULE_STATUS_WD_ADDED as u32;
1254 #[allow(missing_docs)]
1255 const WD_DELETED = raw::GIT_SUBMODULE_STATUS_WD_DELETED as u32;
1256 #[allow(missing_docs)]
1257 const WD_MODIFIED = raw::GIT_SUBMODULE_STATUS_WD_MODIFIED as u32;
1258 #[allow(missing_docs)]
1259 const WD_INDEX_MODIFIED =
1260 raw::GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED as u32;
1261 #[allow(missing_docs)]
1262 const WD_WD_MODIFIED = raw::GIT_SUBMODULE_STATUS_WD_WD_MODIFIED as u32;
1263 #[allow(missing_docs)]
1264 const WD_UNTRACKED = raw::GIT_SUBMODULE_STATUS_WD_UNTRACKED as u32;
1265 }
1266 }
1267
1268 impl SubmoduleStatus {
1269 is_bit_set!(is_in_head, SubmoduleStatus::IN_HEAD);
1270 is_bit_set!(is_in_index, SubmoduleStatus::IN_INDEX);
1271 is_bit_set!(is_in_config, SubmoduleStatus::IN_CONFIG);
1272 is_bit_set!(is_in_wd, SubmoduleStatus::IN_WD);
1273 is_bit_set!(is_index_added, SubmoduleStatus::INDEX_ADDED);
1274 is_bit_set!(is_index_deleted, SubmoduleStatus::INDEX_DELETED);
1275 is_bit_set!(is_index_modified, SubmoduleStatus::INDEX_MODIFIED);
1276 is_bit_set!(is_wd_uninitialized, SubmoduleStatus::WD_UNINITIALIZED);
1277 is_bit_set!(is_wd_added, SubmoduleStatus::WD_ADDED);
1278 is_bit_set!(is_wd_deleted, SubmoduleStatus::WD_DELETED);
1279 is_bit_set!(is_wd_modified, SubmoduleStatus::WD_MODIFIED);
1280 is_bit_set!(is_wd_wd_modified, SubmoduleStatus::WD_WD_MODIFIED);
1281 is_bit_set!(is_wd_untracked, SubmoduleStatus::WD_UNTRACKED);
1282 }
1283
1284 /// Submodule ignore values
1285 ///
1286 /// These values represent settings for the `submodule.$name.ignore`
1287 /// configuration value which says how deeply to look at the working
1288 /// directory when getting the submodule status.
1289 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1290 pub enum SubmoduleIgnore {
1291 /// Use the submodule's configuration
1292 Unspecified,
1293 /// Any change or untracked file is considered dirty
1294 None,
1295 /// Only dirty if tracked files have changed
1296 Untracked,
1297 /// Only dirty if HEAD has moved
1298 Dirty,
1299 /// Never dirty
1300 All,
1301 }
1302
1303 /// Submodule update values
1304 ///
1305 /// These values represent settings for the `submodule.$name.update`
1306 /// configuration value which says how to handle `git submodule update`
1307 /// for this submodule. The value is usually set in the ".gitmodules"
1308 /// file and copied to ".git/config" when the submodule is initialized.
1309 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1310 pub enum SubmoduleUpdate {
1311 /// The default; when a submodule is updated, checkout the new detached
1312 /// HEAD to the submodule directory.
1313 Checkout,
1314 /// Update by rebasing the current checked out branch onto the commit from
1315 /// the superproject.
1316 Rebase,
1317 /// Update by merging the commit in the superproject into the current
1318 /// checkout out branch of the submodule.
1319 Merge,
1320 /// Do not update this submodule even when the commit in the superproject
1321 /// is updated.
1322 None,
1323 /// Not used except as static initializer when we don't want any particular
1324 /// update rule to be specified.
1325 Default,
1326 }
1327
1328 bitflags! {
1329 /// ...
1330 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1331 pub struct PathspecFlags: u32 {
1332 /// Use the default pathspec matching configuration.
1333 const DEFAULT = raw::GIT_PATHSPEC_DEFAULT as u32;
1334 /// Force matching to ignore case, otherwise matching will use native
1335 /// case sensitivity of the platform filesystem.
1336 const IGNORE_CASE = raw::GIT_PATHSPEC_IGNORE_CASE as u32;
1337 /// Force case sensitive matches, otherwise match will use the native
1338 /// case sensitivity of the platform filesystem.
1339 const USE_CASE = raw::GIT_PATHSPEC_USE_CASE as u32;
1340 /// Disable glob patterns and just use simple string comparison for
1341 /// matching.
1342 const NO_GLOB = raw::GIT_PATHSPEC_NO_GLOB as u32;
1343 /// Means that match functions return the error code `NotFound` if no
1344 /// matches are found. By default no matches is a success.
1345 const NO_MATCH_ERROR = raw::GIT_PATHSPEC_NO_MATCH_ERROR as u32;
1346 /// Means that the list returned should track which patterns matched
1347 /// which files so that at the end of the match we can identify patterns
1348 /// that did not match any files.
1349 const FIND_FAILURES = raw::GIT_PATHSPEC_FIND_FAILURES as u32;
1350 /// Means that the list returned does not need to keep the actual
1351 /// matching filenames. Use this to just test if there were any matches
1352 /// at all or in combination with `PATHSPEC_FAILURES` to validate a
1353 /// pathspec.
1354 const FAILURES_ONLY = raw::GIT_PATHSPEC_FAILURES_ONLY as u32;
1355 }
1356 }
1357
1358 impl PathspecFlags {
1359 is_bit_set!(is_default, PathspecFlags::DEFAULT);
1360 is_bit_set!(is_ignore_case, PathspecFlags::IGNORE_CASE);
1361 is_bit_set!(is_use_case, PathspecFlags::USE_CASE);
1362 is_bit_set!(is_no_glob, PathspecFlags::NO_GLOB);
1363 is_bit_set!(is_no_match_error, PathspecFlags::NO_MATCH_ERROR);
1364 is_bit_set!(is_find_failures, PathspecFlags::FIND_FAILURES);
1365 is_bit_set!(is_failures_only, PathspecFlags::FAILURES_ONLY);
1366 }
1367
1368 impl Default for PathspecFlags {
1369 fn default() -> Self {
1370 PathspecFlags::DEFAULT
1371 }
1372 }
1373
1374 bitflags! {
1375 /// Types of notifications emitted from checkouts.
1376 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1377 pub struct CheckoutNotificationType: u32 {
1378 /// Notification about a conflict.
1379 const CONFLICT = raw::GIT_CHECKOUT_NOTIFY_CONFLICT as u32;
1380 /// Notification about a dirty file.
1381 const DIRTY = raw::GIT_CHECKOUT_NOTIFY_DIRTY as u32;
1382 /// Notification about an updated file.
1383 const UPDATED = raw::GIT_CHECKOUT_NOTIFY_UPDATED as u32;
1384 /// Notification about an untracked file.
1385 const UNTRACKED = raw::GIT_CHECKOUT_NOTIFY_UNTRACKED as u32;
1386 /// Notification about an ignored file.
1387 const IGNORED = raw::GIT_CHECKOUT_NOTIFY_IGNORED as u32;
1388 }
1389 }
1390
1391 impl CheckoutNotificationType {
1392 is_bit_set!(is_conflict, CheckoutNotificationType::CONFLICT);
1393 is_bit_set!(is_dirty, CheckoutNotificationType::DIRTY);
1394 is_bit_set!(is_updated, CheckoutNotificationType::UPDATED);
1395 is_bit_set!(is_untracked, CheckoutNotificationType::UNTRACKED);
1396 is_bit_set!(is_ignored, CheckoutNotificationType::IGNORED);
1397 }
1398
1399 /// Possible output formats for diff data
1400 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1401 pub enum DiffFormat {
1402 /// full git diff
1403 Patch,
1404 /// just the headers of the patch
1405 PatchHeader,
1406 /// like git diff --raw
1407 Raw,
1408 /// like git diff --name-only
1409 NameOnly,
1410 /// like git diff --name-status
1411 NameStatus,
1412 /// git diff as used by git patch-id
1413 PatchId,
1414 }
1415
1416 bitflags! {
1417 /// Formatting options for diff stats
1418 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1419 pub struct DiffStatsFormat: raw::git_diff_stats_format_t {
1420 /// Don't generate any stats
1421 const NONE = raw::GIT_DIFF_STATS_NONE;
1422 /// Equivalent of `--stat` in git
1423 const FULL = raw::GIT_DIFF_STATS_FULL;
1424 /// Equivalent of `--shortstat` in git
1425 const SHORT = raw::GIT_DIFF_STATS_SHORT;
1426 /// Equivalent of `--numstat` in git
1427 const NUMBER = raw::GIT_DIFF_STATS_NUMBER;
1428 /// Extended header information such as creations, renames and mode
1429 /// changes, equivalent of `--summary` in git
1430 const INCLUDE_SUMMARY = raw::GIT_DIFF_STATS_INCLUDE_SUMMARY;
1431 }
1432 }
1433
1434 impl DiffStatsFormat {
1435 is_bit_set!(is_none, DiffStatsFormat::NONE);
1436 is_bit_set!(is_full, DiffStatsFormat::FULL);
1437 is_bit_set!(is_short, DiffStatsFormat::SHORT);
1438 is_bit_set!(is_number, DiffStatsFormat::NUMBER);
1439 is_bit_set!(is_include_summary, DiffStatsFormat::INCLUDE_SUMMARY);
1440 }
1441
1442 /// Automatic tag following options.
1443 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1444 pub enum AutotagOption {
1445 /// Use the setting from the remote's configuration
1446 Unspecified,
1447 /// Ask the server for tags pointing to objects we're already downloading
1448 Auto,
1449 /// Don't ask for any tags beyond the refspecs
1450 None,
1451 /// Ask for all the tags
1452 All,
1453 }
1454
1455 /// Configuration for how pruning is done on a fetch
1456 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1457 pub enum FetchPrune {
1458 /// Use the setting from the configuration
1459 Unspecified,
1460 /// Force pruning on
1461 On,
1462 /// Force pruning off
1463 Off,
1464 }
1465
1466 /// Current progress of an operation to apply a stashed change
1467 ///
1468 /// See [`StashApplyOptions::progress_cb()`] for further details.
1469 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
1470 pub enum StashApplyProgress {
1471 /// None
1472 None,
1473 /// Loading the stashed data from the object database
1474 LoadingStash,
1475 /// The stored index is being analyzed
1476 AnalyzeIndex,
1477 /// The modified files are being analyzed
1478 AnalyzeModified,
1479 /// The untracked and ignored files are being analyzed
1480 AnalyzeUntracked,
1481 /// The untracked files are being written to disk
1482 CheckoutUntracked,
1483 /// The modified files are being written to disk
1484 CheckoutModified,
1485 /// The stash was applied successfully
1486 Done,
1487 }
1488
1489 bitflags! {
1490 /// Flags for applying stashed changes
1491 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1492 pub struct StashApplyFlags: u32 {
1493 /// Default options if no additional customization is desired.
1494 const DEFAULT = raw::GIT_STASH_APPLY_DEFAULT as u32;
1495 /// Try to reinstate not only the working tree's changes,
1496 /// but also the index's changes.
1497 const REINSTATE_INDEX = raw::GIT_STASH_APPLY_REINSTATE_INDEX as u32;
1498 }
1499 }
1500
1501 impl StashApplyFlags {
1502 is_bit_set!(is_default, StashApplyFlags::DEFAULT);
1503 is_bit_set!(is_reinstate_index, StashApplyFlags::REINSTATE_INDEX);
1504 }
1505
1506 impl Default for StashApplyFlags {
1507 fn default() -> Self {
1508 StashApplyFlags::DEFAULT
1509 }
1510 }
1511
1512 bitflags! {
1513 /// Flags for use when stashing changes
1514 ///
1515 /// See [`StashSaveOptions::flags()`] and [`Repository::stash_save()`] for
1516 /// further details.
1517 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1518 pub struct StashFlags: u32 {
1519 /// Default options if no additional customization is desired.
1520 const DEFAULT = raw::GIT_STASH_DEFAULT as u32;
1521 /// All changes already added to the index are left intact in
1522 /// the working directory
1523 const KEEP_INDEX = raw::GIT_STASH_KEEP_INDEX as u32;
1524 /// All untracked files are also stashed and then cleaned up
1525 /// from the working directory
1526 const INCLUDE_UNTRACKED = raw::GIT_STASH_INCLUDE_UNTRACKED as u32;
1527 /// All ignored files are also stashed and then cleaned up from
1528 /// the working directory
1529 const INCLUDE_IGNORED = raw::GIT_STASH_INCLUDE_IGNORED as u32;
1530 /// All changes in the index and working directory are left intact
1531 const KEEP_ALL = raw::GIT_STASH_KEEP_ALL as u32;
1532 }
1533 }
1534
1535 impl StashFlags {
1536 is_bit_set!(is_default, StashFlags::DEFAULT);
1537 is_bit_set!(is_keep_index, StashFlags::KEEP_INDEX);
1538 is_bit_set!(is_include_untracked, StashFlags::INCLUDE_UNTRACKED);
1539 is_bit_set!(is_include_ignored, StashFlags::INCLUDE_IGNORED);
1540 }
1541
1542 impl Default for StashFlags {
1543 fn default() -> Self {
1544 StashFlags::DEFAULT
1545 }
1546 }
1547
1548 bitflags! {
1549 #[allow(missing_docs)]
1550 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1551 pub struct AttrCheckFlags: u32 {
1552 /// Check the working directory, then the index.
1553 const FILE_THEN_INDEX = raw::GIT_ATTR_CHECK_FILE_THEN_INDEX as u32;
1554 /// Check the index, then the working directory.
1555 const INDEX_THEN_FILE = raw::GIT_ATTR_CHECK_INDEX_THEN_FILE as u32;
1556 /// Check the index only.
1557 const INDEX_ONLY = raw::GIT_ATTR_CHECK_INDEX_ONLY as u32;
1558 /// Do not use the system gitattributes file.
1559 const NO_SYSTEM = raw::GIT_ATTR_CHECK_NO_SYSTEM as u32;
1560 }
1561 }
1562
1563 impl Default for AttrCheckFlags {
1564 fn default() -> Self {
1565 AttrCheckFlags::FILE_THEN_INDEX
1566 }
1567 }
1568
1569 bitflags! {
1570 /// Flags for a [`DiffDelta`]
1571 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1572 pub struct DiffFlags: u32 {
1573 /// File(s) treated as binary data.
1574 const BINARY = raw::GIT_DIFF_FLAG_BINARY as u32;
1575 /// File(s) treated as text data.
1576 const NOT_BINARY = raw::GIT_DIFF_FLAG_NOT_BINARY as u32;
1577 /// `id` value is known correct.
1578 const VALID_ID = raw::GIT_DIFF_FLAG_VALID_ID as u32;
1579 /// File exists at this side of the delta.
1580 const EXISTS = raw::GIT_DIFF_FLAG_EXISTS as u32;
1581 }
1582 }
1583
1584 impl DiffFlags {
1585 is_bit_set!(is_binary, DiffFlags::BINARY);
1586 is_bit_set!(is_not_binary, DiffFlags::NOT_BINARY);
1587 is_bit_set!(has_valid_id, DiffFlags::VALID_ID);
1588 is_bit_set!(exists, DiffFlags::EXISTS);
1589 }
1590
1591 bitflags! {
1592 /// Options for [`Reference::normalize_name`].
1593 #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
1594 pub struct ReferenceFormat: u32 {
1595 /// No particular normalization.
1596 const NORMAL = raw::GIT_REFERENCE_FORMAT_NORMAL as u32;
1597 /// Control whether one-level refname are accepted (i.e., refnames that
1598 /// do not contain multiple `/`-separated components). Those are
1599 /// expected to be written only using uppercase letters and underscore
1600 /// (e.g. `HEAD`, `FETCH_HEAD`).
1601 const ALLOW_ONELEVEL = raw::GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL as u32;
1602 /// Interpret the provided name as a reference pattern for a refspec (as
1603 /// used with remote repositories). If this option is enabled, the name
1604 /// is allowed to contain a single `*` in place of a full pathname
1605 /// components (e.g., `foo/*/bar` but not `foo/bar*`).
1606 const REFSPEC_PATTERN = raw::GIT_REFERENCE_FORMAT_REFSPEC_PATTERN as u32;
1607 /// Interpret the name as part of a refspec in shorthand form so the
1608 /// `ALLOW_ONELEVEL` naming rules aren't enforced and `main` becomes a
1609 /// valid name.
1610 const REFSPEC_SHORTHAND = raw::GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND as u32;
1611 }
1612 }
1613
1614 impl ReferenceFormat {
1615 is_bit_set!(is_allow_onelevel, ReferenceFormat::ALLOW_ONELEVEL);
1616 is_bit_set!(is_refspec_pattern, ReferenceFormat::REFSPEC_PATTERN);
1617 is_bit_set!(is_refspec_shorthand, ReferenceFormat::REFSPEC_SHORTHAND);
1618 }
1619
1620 impl Default for ReferenceFormat {
1621 fn default() -> Self {
1622 ReferenceFormat::NORMAL
1623 }
1624 }
1625
1626 #[cfg(test)]
1627 mod tests {
1628 use super::{FileMode, ObjectType};
1629
1630 #[test]
1631 fn convert() {
1632 assert_eq!(ObjectType::Blob.str(), "blob");
1633 assert_eq!(ObjectType::from_str("blob"), Some(ObjectType::Blob));
1634 assert!(ObjectType::Blob.is_loose());
1635 }
1636
1637 #[test]
1638 fn convert_filemode() {
1639 assert_eq!(i32::from(FileMode::Blob), 0o100644);
1640 assert_eq!(i32::from(FileMode::BlobGroupWritable), 0o100664);
1641 assert_eq!(i32::from(FileMode::BlobExecutable), 0o100755);
1642 assert_eq!(u32::from(FileMode::Blob), 0o100644);
1643 assert_eq!(u32::from(FileMode::BlobGroupWritable), 0o100664);
1644 assert_eq!(u32::from(FileMode::BlobExecutable), 0o100755);
1645 }
1646
1647 #[test]
1648 fn bitflags_partial_eq() {
1649 use super::{
1650 AttrCheckFlags, CheckoutNotificationType, CredentialType, DiffFlags, DiffStatsFormat,
1651 IndexAddOption, IndexEntryExtendedFlag, IndexEntryFlag, MergeAnalysis, MergePreference,
1652 OdbLookupFlags, PathspecFlags, ReferenceFormat, RepositoryInitMode,
1653 RepositoryOpenFlags, RevparseMode, Sort, StashApplyFlags, StashFlags, Status,
1654 SubmoduleStatus,
1655 };
1656
1657 assert_eq!(
1658 AttrCheckFlags::FILE_THEN_INDEX,
1659 AttrCheckFlags::FILE_THEN_INDEX
1660 );
1661 assert_eq!(
1662 CheckoutNotificationType::CONFLICT,
1663 CheckoutNotificationType::CONFLICT
1664 );
1665 assert_eq!(
1666 CredentialType::USER_PASS_PLAINTEXT,
1667 CredentialType::USER_PASS_PLAINTEXT
1668 );
1669 assert_eq!(DiffFlags::BINARY, DiffFlags::BINARY);
1670 assert_eq!(
1671 DiffStatsFormat::INCLUDE_SUMMARY,
1672 DiffStatsFormat::INCLUDE_SUMMARY
1673 );
1674 assert_eq!(
1675 IndexAddOption::CHECK_PATHSPEC,
1676 IndexAddOption::CHECK_PATHSPEC
1677 );
1678 assert_eq!(
1679 IndexEntryExtendedFlag::INTENT_TO_ADD,
1680 IndexEntryExtendedFlag::INTENT_TO_ADD
1681 );
1682 assert_eq!(IndexEntryFlag::EXTENDED, IndexEntryFlag::EXTENDED);
1683 assert_eq!(
1684 MergeAnalysis::ANALYSIS_FASTFORWARD,
1685 MergeAnalysis::ANALYSIS_FASTFORWARD
1686 );
1687 assert_eq!(
1688 MergePreference::FASTFORWARD_ONLY,
1689 MergePreference::FASTFORWARD_ONLY
1690 );
1691 assert_eq!(OdbLookupFlags::NO_REFRESH, OdbLookupFlags::NO_REFRESH);
1692 assert_eq!(PathspecFlags::FAILURES_ONLY, PathspecFlags::FAILURES_ONLY);
1693 assert_eq!(
1694 ReferenceFormat::ALLOW_ONELEVEL,
1695 ReferenceFormat::ALLOW_ONELEVEL
1696 );
1697 assert_eq!(
1698 RepositoryInitMode::SHARED_ALL,
1699 RepositoryInitMode::SHARED_ALL
1700 );
1701 assert_eq!(RepositoryOpenFlags::CROSS_FS, RepositoryOpenFlags::CROSS_FS);
1702 assert_eq!(RevparseMode::RANGE, RevparseMode::RANGE);
1703 assert_eq!(Sort::REVERSE, Sort::REVERSE);
1704 assert_eq!(
1705 StashApplyFlags::REINSTATE_INDEX,
1706 StashApplyFlags::REINSTATE_INDEX
1707 );
1708 assert_eq!(StashFlags::INCLUDE_IGNORED, StashFlags::INCLUDE_IGNORED);
1709 assert_eq!(Status::WT_MODIFIED, Status::WT_MODIFIED);
1710 assert_eq!(SubmoduleStatus::WD_ADDED, SubmoduleStatus::WD_ADDED);
1711 }
1712 }