Skip to content

Commit

Permalink
grow: set remote.<name>.tagopt to --no-tags on remotes
Browse files Browse the repository at this point in the history
Do not fetch tags by default for additional remotes.
This makes it safer to interact with them using "git fetch"
because tag downloading becomes an opt-in behavior.
  • Loading branch information
davvid committed Aug 31, 2023
1 parent 9162308 commit 5326b15
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
8 changes: 8 additions & 0 deletions doc/src/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v0.9.0

**Features**

- `garden grow` now sets `git config remote.$name.tagopt --no-tags`
when adding additional remotes. This prevents accidentally fetching tags
when interacting with remotes.

## v0.8.1

**Fixes**:
Expand Down
29 changes: 22 additions & 7 deletions src/cmds/grow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,39 @@ fn update_tree_from_context(
ctx.garden.as_ref(),
);

let exec = if existing_remotes.contains(remote) {
if existing_remotes.contains(remote) {
let remote_key = format!("remote.{remote}.url");
let command = ["git", "config", remote_key.as_ref(), url.as_ref()];
if verbose > 1 {
print_command_str(&command.join(" "));
}
cmd::exec_in_dir(&command, path)
let exec = cmd::exec_in_dir(&command, path);
let status = cmd::status(exec.join());
if status != errors::EX_OK {
exit_status = status;
}
} else {
let command = ["git", "remote", "add", remote.as_ref(), url.as_ref()];
if verbose > 1 {
print_command_str(&command.join(" "));
}
cmd::exec_in_dir(&command, path)
};
let exec = cmd::exec_in_dir(&command, path);
let status = cmd::status(exec.join());
if status != errors::EX_OK {
exit_status = status;
}

let status = cmd::status(exec.join());
if status != errors::EX_OK {
exit_status = status;
// git config remote.<name>.tagopt --no-tags
let key = format!("remote.{}.tagopt", remote);
let command = ["git", "config", key.as_ref(), "--no-tags"];
if verbose > 1 {
print_command_str(&command.join(" "));
}
let exec = cmd::exec_in_dir(&command, path);
let status = cmd::status(exec.join());
if status != errors::EX_OK {
exit_status = status;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ fn grow_remotes() -> Result<()> {
let output = assert_cmd_capture(&cmd, &worktree);
assert_eq!("git@github.com:user/example.git", output);

// remote.publish.tagopt is --no-tags
let cmd = ["git", "config", "remote.publish.tagopt"];
let output = assert_cmd_capture(&cmd, &worktree);
assert_eq!("--no-tags", output);

Ok(())
}

Expand Down

0 comments on commit 5326b15

Please sign in to comment.