Skip to content

cleanup and init a bare repository #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[config #185] add test for handling windows formatted files…
…which occour implicitly when checking out the repository fixtures on
windows, which are then windows formatted. From there the unholy
carriage return \r enters the compiled binary using include_bytes!
as a template, which then is used to initialize a repository.

In case of bare repositories, the implementation has to check if
it really is bare (i.e. bare = true) or just looks bare (because
there is no index, but that's the case in a new repository as well).

This check would use the config parser, which wouldn't consider carriage
returns and fail to parse the config file, making the opening of
repositories impossible on windows.
  • Loading branch information
Byron committed Aug 30, 2021
commit 2a2a89f68cc45e27a1cf0d33fc644ebabc762302
2 changes: 1 addition & 1 deletion git-config/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ fn take_spaces(i: &[u8]) -> IResult<&[u8], &str> {

fn take_newline(i: &[u8]) -> IResult<&[u8], (&str, usize)> {
let mut counter = 0;
let (i, v) = take_while(|c| (c as char).is_ascii() && is_newline(c))(i)?;
let (i, v) = take_while(|c| (c as char).is_ascii() && (c == b'\r' || is_newline(c)))(i)?;
counter += v.len();
if v.is_empty() {
Err(nom::Err::Error(NomError {
Expand Down
14 changes: 14 additions & 0 deletions git-config/tests/fixtures/repo-config.crlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
; hello
# world

[core]
repositoryformatversion = 0
bare = true
[other]
repositoryformatversion = 0

bare = true

# before section with newline
[foo]
repositoryformatversion = 0
8 changes: 8 additions & 0 deletions git-config/tests/integration_tests/file_integeration_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use std::{borrow::Cow, convert::TryFrom};

use git_config::{file::GitConfig, values::*};
use std::path::Path;

#[test]
fn parse_config_with_windows_line_endings_successfully() {
GitConfig::open(Path::new("tests").join("fixtures").join("repo-config.crlf"))
.map_err(|err| err.to_string())
.unwrap();
}

/// Asserts we can cast into all variants of our type
#[test]
Expand Down