mod support;
use std::fs;
use tempfile::TempDir;
use thoughts_tool::git::shell_push::push_current_branch;
#[ignore = "integration test - run with: just test-integration"]
#[test]
fn push_to_bare_remote_with_shell_git() {
let remote = TempDir::new().unwrap();
support::git_ok(remote.path(), &["init", "--bare", "."]);
let local = TempDir::new().unwrap();
support::git_ok(local.path(), &["init"]);
fs::write(local.path().join("c.txt"), "hello").unwrap();
support::git_ok(local.path(), &["add", "."]);
support::git_ok(
local.path(),
&[
"-c",
"user.name=Test",
"-c",
"user.email=test@example.com",
"commit",
"-m",
"init",
],
);
support::git_ok(local.path(), &["branch", "-M", "main"]);
support::git_ok(
local.path(),
&["remote", "add", "origin", remote.path().to_str().unwrap()],
);
push_current_branch(local.path(), "origin", "main").expect("push should succeed");
let stdout = support::git_stdout(remote.path(), &["ls-remote", ".", "refs/heads/main"]);
assert!(stdout.contains("refs/heads/main"));
}
#[ignore = "integration test - run with: just test-integration"]
#[test]
fn push_additional_commit() {
let remote = TempDir::new().unwrap();
support::git_ok(remote.path(), &["init", "--bare", "."]);
let local = TempDir::new().unwrap();
support::git_ok(local.path(), &["init"]);
fs::write(local.path().join("a.txt"), "first").unwrap();
support::git_ok(local.path(), &["add", "."]);
support::git_ok(
local.path(),
&[
"-c",
"user.name=Test",
"-c",
"user.email=test@example.com",
"commit",
"-m",
"first",
],
);
support::git_ok(local.path(), &["branch", "-M", "main"]);
support::git_ok(
local.path(),
&["remote", "add", "origin", remote.path().to_str().unwrap()],
);
push_current_branch(local.path(), "origin", "main").expect("first push should succeed");
let first_sha = support::git_stdout(local.path(), &["rev-parse", "HEAD"]);
fs::write(local.path().join("b.txt"), "second").unwrap();
support::git_ok(local.path(), &["add", "."]);
support::git_ok(
local.path(),
&[
"-c",
"user.name=Test",
"-c",
"user.email=test@example.com",
"commit",
"-m",
"second",
],
);
let second_sha = support::git_stdout(local.path(), &["rev-parse", "HEAD"]);
push_current_branch(local.path(), "origin", "main").expect("second push should succeed");
let stdout = support::git_stdout(remote.path(), &["ls-remote", ".", "refs/heads/main"]);
assert!(stdout.contains(&second_sha));
assert!(!stdout.contains(&first_sha)); }
#[ignore = "integration test - run with: just test-integration"]
#[test]
fn push_nothing_to_push_succeeds() {
let remote = TempDir::new().unwrap();
support::git_ok(remote.path(), &["init", "--bare", "."]);
let local = TempDir::new().unwrap();
support::git_ok(local.path(), &["init"]);
fs::write(local.path().join("a.txt"), "content").unwrap();
support::git_ok(local.path(), &["add", "."]);
support::git_ok(
local.path(),
&[
"-c",
"user.name=Test",
"-c",
"user.email=test@example.com",
"commit",
"-m",
"init",
],
);
support::git_ok(local.path(), &["branch", "-M", "main"]);
support::git_ok(
local.path(),
&["remote", "add", "origin", remote.path().to_str().unwrap()],
);
push_current_branch(local.path(), "origin", "main").expect("first push should succeed");
push_current_branch(local.path(), "origin", "main")
.expect("push with nothing to push should succeed");
}