forked from attaca/attaca
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
363 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use chrono::prelude::*; | ||
use clap::{App, SubCommand, Arg, ArgMatches}; | ||
use futures::prelude::*; | ||
use globset::{Glob, GlobSetBuilder}; | ||
|
||
use attaca::Repository; | ||
use attaca::repository::Head; | ||
|
||
use errors::*; | ||
use trace::Progress; | ||
|
||
|
||
pub fn command() -> App<'static, 'static> { | ||
SubCommand::with_name("commit") | ||
.help("Commit a change to the local repository.") | ||
.arg( | ||
Arg::with_name("INCLUDE") | ||
.short("i") | ||
.long("inc") | ||
.takes_value(true) | ||
.multiple(true) | ||
.help( | ||
"Zero or more patterns matching files to include in the commit.", | ||
), | ||
) | ||
.arg( | ||
Arg::with_name("EXCLUDE") | ||
.short("e") | ||
.long("exc") | ||
.takes_value(true) | ||
.multiple(true) | ||
.help( | ||
"Zero or more patterns matching files to exclude from the commit.", | ||
), | ||
) | ||
.arg(Arg::with_name("MESSAGE").index(1).required(true).help( | ||
"The commit message.", | ||
)) | ||
} | ||
|
||
|
||
pub fn go(repository: &mut Repository, matches: &ArgMatches) -> Result<()> { | ||
let include = if let Some(paths) = matches.values_of("INCLUDE") { | ||
let mut builder = GlobSetBuilder::new(); | ||
for path in paths { | ||
builder.add(Glob::new(path)?); | ||
} | ||
Some(builder.build()?) | ||
} else { | ||
None | ||
}; | ||
|
||
let exclude = if let Some(paths) = matches.values_of("EXCLUDE") { | ||
let mut builder = GlobSetBuilder::new(); | ||
for path in paths { | ||
builder.add(Glob::new(path)?); | ||
} | ||
Some(builder.build()?) | ||
} else { | ||
None | ||
}; | ||
|
||
let message = matches.value_of("MESSAGE").unwrap().to_owned(); | ||
|
||
repository.index.update()?; | ||
|
||
let commit_hash = { | ||
let mut ctx = repository.local(Progress::new(None))?; | ||
let head = ctx.refs.head_hash().cloned().into_iter().collect(); | ||
ctx.hash_commit( | ||
include.as_ref(), | ||
exclude.as_ref(), | ||
head, | ||
message, | ||
Utc::now(), | ||
).wait()? | ||
}; | ||
|
||
repository.refs.head = Head::Detached(commit_hash); | ||
repository.index.iter_mut().for_each( | ||
|(_, entry)| entry.added = false, | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use clap::{App, SubCommand, ArgMatches}; | ||
|
||
use attaca::Repository; | ||
use attaca::index::Cached; | ||
use errors::*; | ||
|
||
|
||
pub fn command() -> App<'static, 'static> { | ||
SubCommand::with_name("status").about("Show repository status, including tracked/added files.") | ||
} | ||
|
||
|
||
pub fn go(repository: &mut Repository, _matches: &ArgMatches) -> Result<()> { | ||
repository.index.update()?; | ||
|
||
let catalog = repository.catalogs.get(None)?; | ||
println!("{} local objects.", catalog.len()); | ||
|
||
let mut added = Vec::new(); | ||
let mut tracked = Vec::new(); | ||
|
||
for (path, entry) in repository.index.iter() { | ||
if entry.tracked { | ||
tracked.push((path, entry)); | ||
} else if entry.added { | ||
added.push((path, entry)); | ||
} | ||
} | ||
|
||
println!("Tracked:"); | ||
|
||
for (path, entry) in tracked { | ||
match entry.cached { | ||
Cached::Hashed(hashed) => { | ||
println!( | ||
"\t[{:?}] {} Hashed({})", | ||
entry.hygiene, | ||
path.display(), | ||
&hashed.to_string()[..6] | ||
) | ||
} | ||
Cached::Unhashed => println!("\t[{:?}] {} Unhashed", entry.hygiene, path.display()), | ||
Cached::Removed => println!("\t[{:?}] {} Removed", entry.hygiene, path.display()), | ||
} | ||
} | ||
|
||
println!("Added:"); | ||
|
||
for (path, entry) in added { | ||
match entry.cached { | ||
Cached::Hashed(hashed) => { | ||
println!( | ||
"\t[{:?}] {} Hashed({})", | ||
entry.hygiene, | ||
path.display(), | ||
&hashed.to_string()[..6] | ||
) | ||
} | ||
Cached::Unhashed => println!("\t[{:?}] {} Unhashed", entry.hygiene, path.display()), | ||
Cached::Removed => println!("\t[{:?}] {} Removed", entry.hygiene, path.display()), | ||
} | ||
} | ||
|
||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.