Skip to content

Add "remote add" command [WIP] - #335

Draft
MarcoSteinacher wants to merge 3 commits into
bc-break/rewrite-in-rustfrom
rust/remote_add
Draft

MarcoSteinacher wants to merge 3 commits into
bc-break/rewrite-in-rustfrom
rust/remote_add

Conversation

@MarcoSteinacher

Copy link
Copy Markdown
Member

I confirm that I have read the Contributor Agreement v1.1, agree to be bound on them and confirm that my contribution is compliant.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR is a WIP step toward porting gt remote add from the existing bash implementation to Rust, adding supporting utilities for user prompting and working-directory remote metadata.

Changes:

  • Implemented a first Rust version of gt remote add using git2 and gpgme, plus initial unit tests.
  • Added Rust utilities for pulled.tsv/pull.args handling and a reusable yes/no prompt helper.
  • Wired new modules into the Rust binary and added required Rust dependencies.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
TASK.md Adds implementation checklist for the Rust remote add port.
src/utils.rs Adds interactive yes/no prompting utilities and related tests.
src/pulled-utils.rs Introduces Rust helpers for pulled.tsv and pull.args I/O.
src/main.rs Registers new pulled_utils and utils modules.
src/commands/remote/add.rs Implements gt remote add in Rust (git remote init/fetch + GPG key import) and adds tests.
Cargo.toml Adds git2, gpgme, and tempfile dependencies.
Cargo.lock Updates lockfile for new dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TASK.md
Comment on lines +7 to +10
1. Read the current bash implementation in function `gt_remote_add()` in `src/gt-remote.sh`
3. Implement the remote add in rust in `src/commands/remote/add.rs`.
4. Write tests for the command in the same file.
5. Verify that the code compiles, passes the linter and formatter, and that all tests pass.
Comment thread src/utils.rs
Comment on lines +38 to +48
/// Like `ask_yes_no`, but repeats until the user gives a clear yes or no answer.
pub fn ask_yes_no_loop(prompt: &str) -> io::Result<bool> {
loop {
let answer = ask_yes_no(prompt)?;
// ask_yes_no already returns false for anything except y/yes.
// To mirror bash behavior of warning on unknown input, we'd need
// to know if the input was blank vs unknown. For simplicity we
// treat all non-y/yes as "no".
return Ok(answer);
}
}
Comment thread src/utils.rs
Comment on lines +22 to +23
/// Overload that accepts any reader, used for testability.
pub fn ask_yes_no_with_reader<R, W>(prompt: &str, reader: &mut R, writer: &mut W) -> io::Result<bool>
Comment thread src/utils.rs
Comment on lines +50 to +55
#[derive(Debug)]
pub enum GtError {
Io(io::Error),
Validation(String),
}

Comment thread src/pulled-utils.rs
Comment on lines +1 to +3
#![allow(dead_code)]

use std::fs::{self, File};
Comment on lines +493 to +496
working_directory_arg: WorkingDirectoryArg {
working_directory: project.to_path_buf(),
},
};
Comment on lines +508 to +512
let tmp = TempDir::new().unwrap();
let project = tmp.path().join("project");
fs::create_dir(&project).unwrap();
env::set_current_dir(&project).unwrap();

Comment on lines +525 to +528
working_directory_arg: WorkingDirectoryArg {
working_directory: project.to_path_buf(),
},
};
Comment on lines +541 to +549
// Create a bare repo with a .gt directory in its default branch
{
let origin = git2::Repository::init_bare(&bare).unwrap();
let sig = git2::Signature::now("Test", "test@example.com").unwrap();
let tree_id = {
let mut index = origin.index().unwrap();
index.write_tree().unwrap()
};
let tree = origin.find_tree(tree_id).unwrap();
Ok(())
}

fn validate_remote_name(name: &String) -> Result<(), AddError> {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants