summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Grunert <Sascha.Grunert@rohde-schwarz.com>2016-10-06 11:37:13 +0200
committerSascha Grunert <Sascha.Grunert@rohde-schwarz.com>2016-10-06 11:42:33 +0200
commitd46bd11df65bf51911c427270b57d817464ede64 (patch)
tree7e9226694a9246538c5ae0aed0a5229bab8eff65
parentcdc2fee0bcba5dbb46c1e3865be405b7082bdd0e (diff)
Added sorting methods "name" and "date" for the output
-rw-r--r--.gitjournal.toml1
-rw-r--r--README.md4
-rw-r--r--src/config.rs4
-rw-r--r--src/lib.rs14
-rw-r--r--src/parser.rs1
m---------tests/test_repo0
6 files changed, 20 insertions, 4 deletions
diff --git a/.gitjournal.toml b/.gitjournal.toml
index 3baca86..b9bfa01 100644
--- a/.gitjournal.toml
+++ b/.gitjournal.toml
@@ -4,4 +4,5 @@ enable_debug = true
enable_footers = false
excluded_commit_tags = []
show_prefix = false
+sort_by = "date"
template_prefix = "JIRA-1234"
diff --git a/README.md b/README.md
index 9cdb821..f65a4f0 100644
--- a/README.md
+++ b/README.md
@@ -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.
@@ -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
diff --git a/src/config.rs b/src/config.rs
index 8681ce7..efa3db1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -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,
}
@@ -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(),
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 74d6e0b..9645fc9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 {
@@ -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"
/// ```
@@ -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)
}
})
@@ -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());
diff --git a/src/parser.rs b/src/parser.rs
index c192029..5464a5e 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -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));
}
diff --git a/tests/test_repo b/tests/test_repo
-Subproject 516de3e04f789d612386415034a0d970816d116
+Subproject d10fcab711fd73b83d51ed5bbffc263a9a859ed