]>
git.proxmox.com Git - cargo.git/blob - vendor/git2-0.6.8/examples/add.rs
2 * libgit2 "add" example - shows how to modify the index
4 * Written by the libgit2 contributors
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
16 #![allow(trivial_casts)]
21 extern crate serde_derive
;
27 #[derive(Deserialize)]
29 arg_spec
: Vec
<String
>,
35 fn run(args
: &Args
) -> Result
<(), git2
::Error
> {
36 let repo
= try
!(Repository
::open(&Path
::new(".")));
37 let mut index
= try
!(repo
.index());
39 let cb
= &mut |path
: &Path
, _matched_spec
: &[u8]| -> i32 {
40 let status
= repo
.status_file(path
).unwrap();
42 let ret
= if status
.contains(git2
::STATUS_WT_MODIFIED
) ||
43 status
.contains(git2
::STATUS_WT_NEW
) {
44 println
!("add '{}'", path
.display());
50 if args
.flag_dry_run {1}
else {ret}
52 let cb
= if args
.flag_verbose
|| args
.flag_update
{
53 Some(cb
as &mut git2
::IndexMatchedPath
)
59 try
!(index
.update_all(args
.arg_spec
.iter(), cb
));
61 try
!(index
.add_all(args
.arg_spec
.iter(), git2
::ADD_DEFAULT
, cb
));
69 const USAGE
: &'
static str = "
70 usage: add [options] [--] [<spec>..]
74 -v, --verbose be verbose
75 -u, --update update tracked files
76 -h, --help show this message
79 let args
= Docopt
::new(USAGE
).and_then(|d
| d
.deserialize())
80 .unwrap_or_else(|e
| e
.exit());
83 Err(e
) => println
!("error: {}", e
),