Skip to content

Commit

Permalink
Added sorting methods "name" and "date" for the output
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Grunert authored and Sascha Grunert committed Oct 6, 2016
1 parent cdc2fee commit d46bd11
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitjournal.toml
Expand Up @@ -4,4 +4,5 @@ enable_debug = true
enable_footers = false
excluded_commit_tags = []
show_prefix = false
sort_by = "date"
template_prefix = "JIRA-1234"
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -336,6 +336,8 @@ repository:
* [x] Automatic wrapping of commit message categories in square brackets.
* [x] Templating support including tag and name mapping.
* [x] Support for accumulating footer data (also for templating engine).
* [x] Different sorting methods (`"date"` and `"name"`) for the default and template based output.
* [x] Support for custom header and footer fields within templates
* Preparation and Verification of commit messages
* [x] Automatic installation of git hooks inside the local repository.
* [x] Generation of default configuration file during setup.
Expand All @@ -346,9 +348,7 @@ repository:
[planned]: #planned

* [ ] Custom commit message template support, which will be used for commit preparation.
* [ ] Multiple template extensions, like custom header/footer or other different custom fields.
* [ ] Generation of default templates based on commits within a given commit rage.
* [ ] Custom sorting methods for the default and template based output.
* [ ] Commit message validation via provided template

## Contributing
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Expand Up @@ -67,6 +67,9 @@ pub struct Config {
/// Show or hide the commit message prefix, e.g. JIRA-1234
pub show_prefix: bool,

/// Sort the commits during the output by "date" (default) or "name"
pub sort_by: String,

/// Commit message template prefix which will be added during commit preparation
pub template_prefix: String,
}
Expand All @@ -90,6 +93,7 @@ impl Config {
excluded_commit_tags: vec![],
enable_footers: false,
show_prefix: false,
sort_by: "date".to_owned(),
template_prefix: "JIRA-1234".to_owned(),
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/lib.rs
Expand Up @@ -175,7 +175,9 @@ impl GitJournal {

// Search for config in path and load
let mut new_config = Config::new();
new_config.load(path).is_ok();
if let Err(e) = new_config.load(path) {
println_warn!("Can't load configuration file, using default one: {}", e);
}

// Create a new parser with empty results
let new_parser = Parser {
Expand Down Expand Up @@ -229,6 +231,9 @@ impl GitJournal {
/// # Show or hide the commit message prefix, e.g. JIRA-1234
/// show_prefix = false
///
/// # Sort the commits during the output by "date" (default) or "name"
/// sort_by = "date"
///
/// # Commit message template prefix which will be added during commit preparation.
/// template_prefix = "JIRA-1234"
/// ```
Expand Down Expand Up @@ -511,6 +516,11 @@ impl GitJournal {
if parsed_tag.commits.is_empty() {
None
} else {
if self.config.sort_by == "name" {
parsed_tag.commits.sort_by(|l, r| {
l.summary.category.cmp(&r.summary.category)
});
}
Some(parsed_tag)
}
})
Expand Down Expand Up @@ -692,7 +702,7 @@ mod tests {
assert_eq!(journal.config.excluded_commit_tags.len(), 0);
assert!(journal.parse_log("HEAD", "rc", &0, &true, &false).is_ok());
assert_eq!(journal.parser.result.len(), journal.tags.len() + 1);
assert_eq!(journal.parser.result[0].commits.len(), 12);
assert_eq!(journal.parser.result[0].commits.len(), 13);
assert_eq!(journal.parser.result[1].commits.len(), 1);
assert_eq!(journal.parser.result[2].commits.len(), 2);
assert!(journal.print_log(false, None, Some("CHANGELOG.md")).is_ok());
Expand Down
1 change: 1 addition & 0 deletions src/parser.rs
Expand Up @@ -778,6 +778,7 @@ impl Parser {
let mut term = try!(term::stdout().ok_or(Error::Terminal));
let mut vec = vec![];

// Print every tag
for tag in &self.result {
try!(tag.print_to_term_and_write_to_vector(&mut term, &mut vec, compact, config, template));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_repo
Submodule test_repo updated 1 files
+1 −0 .gitjournal.toml

0 comments on commit d46bd11

Please sign in to comment.