Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ impl Config {

for line in stdout.lines() {
if let Some((key, value)) = line.split_once(' ') {
let mut parts = key.split('.');
if parts.next() != Some(CONFIG_PREFIX) {
continue;
}
if let Some(name) = parts.next() {
if let Some(field) = parts.next() {
if let Some(rem) = key.strip_prefix(&format!("{CONFIG_PREFIX}.")) {
if let Some((name, field)) = rem.rsplit_once('.') {
let entry =
cfg.mappings
.entry(name.to_string())
Expand Down
30 changes: 30 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ fn connect_and_list_roundtrip() {
.stdout(predicate::str::contains("app"));
}

#[test]
fn dotted_subdir_and_remote() {
let repo = setup_repo();
let git_shim = fake_git_path(&repo);

let (path_env, orig_path) = path_vars(&git_shim);

Command::cargo_bin("gh-sync")
.unwrap()
.current_dir(repo.path())
.env("PATH", &path_env)
.env("ORIG_PATH", &orig_path)
.args(&[
"connect",
"tools/automaton.x",
"git@github.com:a/automaton.x.git",
])
.assert()
.success();

Command::cargo_bin("gh-sync")
.unwrap()
.current_dir(repo.path())
.env("PATH", &path_env)
.env("ORIG_PATH", &orig_path)
.args(&["pull", "tools/automaton.x"])
.assert()
.success();
Comment on lines +123 to +143
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test is great for covering the dotted name case. However, there's some code duplication in setting up the Command. You can refactor this to improve readability and maintainability by using a closure to create and configure the command.

    let get_cmd = || {
        let mut cmd = Command::cargo_bin("gh-sync").unwrap();
        cmd.current_dir(repo.path())
            .env("PATH", &path_env)
            .env("ORIG_PATH", &orig_path);
        cmd
    };

    get_cmd()
        .args(&[
            "connect",
            "tools/automaton.x",
            "git@github.com:a/automaton.x.git",
        ])
        .assert()
        .success();

    get_cmd()
        .args(&["pull", "tools/automaton.x"])
        .assert()
        .success();

}

#[test]
fn pull_falls_back_to_add() {
let repo = setup_repo();
Expand Down
Loading