Skip to content
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

feat: Recognize changes to remote URLs & support revision option #92

Merged
merged 29 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c61ccd6
feat: support items.revision
bezhermoso Jan 11, 2025
f080723
feat: understand all sorts of revisions
bezhermoso Jan 11, 2025
b0c6c5a
fix: use spec-0.11 as schemes revision value
bezhermoso Jan 11, 2025
6aa0291
wip
bezhermoso Jan 11, 2025
fcda162
feat: atomic updates
bezhermoso Jan 12, 2025
9d5597b
chore: remove git_pull, now unused
bezhermoso Jan 12, 2025
91f5701
style: format
bezhermoso Jan 12, 2025
624299f
fix: pass --quiet flags to certain git commands
bezhermoso Jan 12, 2025
1f02fb7
style: call .args(...) before .current_dir(...) for continuity
bezhermoso Jan 12, 2025
efaee76
wip: resolve SHA1 without rev-parse
bezhermoso Jan 13, 2025
ecf2341
fix: use Cargo.lock version 3
bezhermoso Jan 13, 2025
4948e60
fix: stop using rev-parse
bezhermoso Jan 13, 2025
58da50e
wip: specify cargo-deny as a dependency
bezhermoso Jan 13, 2025
a722083
fix: stdout handling
bezhermoso Jan 13, 2025
df2cc19
fix: fix commit sha1 resolution
bezhermoso Jan 13, 2025
a009f9e
chore: use rust 1.84.0 in cargo deny check
bezhermoso Jan 13, 2025
2a3ab5c
style: rustfmt
bezhermoso Jan 13, 2025
308a284
fix(cargo): remove cargo-deny as dependency, doesn't really work that…
bezhermoso Jan 13, 2025
1c1a0e1
test: test install w/ revision
bezhermoso Jan 13, 2025
a9bd7f2
fix: remove repo path on failed install
bezhermoso Jan 13, 2025
7a2b14b
test: test update & new remote and/or new revision
bezhermoso Jan 13, 2025
98e6756
style: rustfmt
bezhermoso Jan 13, 2025
37d62d2
chore: use safe_command wrapper
bezhermoso Jan 14, 2025
fd4bef1
style: remove comment-out code
bezhermoso Jan 14, 2025
2da77cb
fix: use git diff-index to check if working directory is clean, inclu…
bezhermoso Jan 14, 2025
b74bc2b
style: terser iteration of stdout
bezhermoso Jan 14, 2025
f1d348e
test: improve tests to properly test for exclusivity of revisions
bezhermoso Jan 14, 2025
4f92004
style: is_diff => is_clean
bezhermoso Jan 14, 2025
809d242
doc: update README & CHANGELOG
bezhermoso Jan 14, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1

- uses: EmbarkStudios/cargo-deny-action@v1
with:
rust-version: "1.84.0"
Copy link
Member Author

Choose a reason for hiding this comment

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

@JamyGolden Looks like cargo-deny-action uses an older Rust version than what setup-rust-toolchain uses for the rest.


audit:
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Unreleased

### Added

- Support `[[items]] revision` property that accepts a tag, branch, or commit SHA1.

### Changed

- `tinty update` now keeps the items' `origin` remote URLs up-to-date.
- The item repositories are now checked out to a specific commit SHA1 in "detached HEAD" mode.

### Fixed

- Fix bug where period preceeding extension is still added to generated files even when an extension doesn't exist
Expand Down
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ toml = "0.8.19"
url = "2.5.4"
xdg = "2.5.2"
home = "0.5.11"
rand = "0.8.5"
regex = "1.7"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ themes across different applications seamlessly.
|------------------------|----------|----------|---------------------------------------------------------------|---------|--------------------------------------------|
| `name` | `string` | Required | A unique name for the item being configured. | - | `name = "vim"` |
| `path` | `string` | Required | The file system path or URL to the theme template repository. Paths beginning with `~/` map to home dir. | - | `path = "https://github.com/tinted-tmux"` |
| `revision` | `string` | Optional | The Git revision to use.<br> Accepts a branch name, a tag, or a commit SHA1 | `main` | `revision = "1.2.0"` |
| `themes-dir` | `string` | Required | The directory within the repository where theme files are located. | - | `themes-dir = "colors"` |
| `hook` | `string` | Optional | A command to be executed after the theme is applied. Useful for reloading configurations. `%f` template variable maps to the path of the applied theme file. | None | `hook = "source ~/.vimrc"` |
| `theme-file-extension` | `string` | Optional | Define a custom theme file extension that isn't `/\.*$/`. Tinty looks for themes named `base16-uwunicorn.*` (for example), but when the theme file isn't structured that way, this option can help specify the pattern. | - | `theme-file-extension = ".module.css"` |
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ pub struct ConfigItem {
pub supported_systems: Option<Vec<SchemeSystem>>,
#[serde(rename = "theme-file-extension")]
pub theme_file_extension: Option<String>,
pub revision: Option<String>,
}

impl fmt::Display for ConfigItem {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let hook = self.hook.clone().unwrap_or_default();
let revision = self.revision.clone().unwrap_or_default();
let default_supported_systems = vec![SchemeSystem::default()];
let system_text = self
.supported_systems
Expand All @@ -52,6 +54,9 @@ impl fmt::Display for ConfigItem {
if !hook.is_empty() {
writeln!(f, "hook = \"{}\"", hook)?;
}
if !revision.is_empty() {
writeln!(f, "revision = \"{}\"", revision)?;
}
writeln!(f, "supported-systems = [{}]", system_text)?;
write!(f, "themes-dir = \"{}\"", self.themes_dir)
}
Expand Down Expand Up @@ -108,6 +113,7 @@ impl Config {
hook: Some(BASE16_SHELL_HOOK.to_string()),
supported_systems: Some(vec![SchemeSystem::Base16]), // DEFAULT_SCHEME_SYSTEM
theme_file_extension: None,
revision: None,
};

// Add default `item` if no items exist
Expand Down
1 change: 1 addition & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub const CUSTOM_SCHEMES_DIR_NAME: &str = "custom-schemes";
pub const CURRENT_SCHEME_FILE_NAME: &str = "current_scheme";
pub const DEFAULT_SCHEME_SYSTEM: &str = "base16";
pub const SCHEME_EXTENSION: &str = "yaml";
pub const SCHEMES_REPO_REVISION: &str = "spec-0.11";
7 changes: 5 additions & 2 deletions src/operations/install.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::Config;
use crate::constants::{REPO_DIR, SCHEMES_REPO_NAME, SCHEMES_REPO_URL};
use crate::constants::{REPO_DIR, SCHEMES_REPO_NAME, SCHEMES_REPO_REVISION, SCHEMES_REPO_URL};
use crate::utils::git_clone;
use anyhow::{anyhow, Result};
use std::fs::{remove_file as remove_symlink, symlink_metadata};
Expand All @@ -11,10 +11,11 @@ fn install_git_url(
data_item_path: &Path,
item_name: &str,
item_git_url: &str,
revision: Option<&str>,
is_quiet: bool,
) -> Result<()> {
if !data_item_path.is_dir() {
git_clone(item_git_url, data_item_path)?;
git_clone(item_git_url, data_item_path, revision)?;

if !is_quiet {
println!("{} installed", item_name);
Expand Down Expand Up @@ -86,6 +87,7 @@ pub fn install(config_path: &Path, data_path: &Path, is_quiet: bool) -> Result<(
&data_item_path,
item.name.as_str(),
item.path.as_str(),
item.revision.as_deref(),
is_quiet,
)?,
Err(_) => install_dir(&data_item_path, item.name.as_str(), &item_path, is_quiet)?,
Expand All @@ -98,6 +100,7 @@ pub fn install(config_path: &Path, data_path: &Path, is_quiet: bool) -> Result<(
&schemes_repo_path,
SCHEMES_REPO_NAME,
SCHEMES_REPO_URL,
Some(SCHEMES_REPO_REVISION),
is_quiet,
)?;

Expand Down
35 changes: 27 additions & 8 deletions src/operations/update.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
use crate::constants::{REPO_DIR, SCHEMES_REPO_NAME, SCHEMES_REPO_URL};
use crate::utils::{git_diff, git_pull};
use crate::constants::{REPO_DIR, SCHEMES_REPO_NAME, SCHEMES_REPO_REVISION, SCHEMES_REPO_URL};
use crate::utils::{git_is_working_dir_clean, git_update};
use crate::{config::Config, constants::REPO_NAME};
use anyhow::{Context, Result};
use std::path::Path;

fn update_item(item_name: &str, item_url: &str, item_path: &Path, is_quiet: bool) -> Result<()> {
fn update_item(
item_name: &str,
item_url: &str,
item_path: &Path,
revision: Option<&str>,
is_quiet: bool,
) -> Result<()> {
if item_path.is_dir() {
let is_diff = git_diff(item_path)?;
let is_clean = git_is_working_dir_clean(item_path)?;

if !is_diff {
git_pull(item_path)
.with_context(|| format!("Error pulling {} from {}", item_name, item_url))?;
if is_clean {
git_update(item_path, item_url, revision).with_context(|| {
format!(
"Error updating {} to {}@{}",
item_name,
item_url,
revision.unwrap_or("main")
)
})?;

if !is_quiet {
println!("{} up to date", item_name);
Expand All @@ -36,7 +48,13 @@ pub fn update(config_path: &Path, data_path: &Path, is_quiet: bool) -> Result<()
for item in items {
let item_path = hooks_path.join(&item.name);

update_item(item.name.as_str(), item.path.as_str(), &item_path, is_quiet)?;
update_item(
item.name.as_str(),
item.path.as_str(),
&item_path,
item.revision.as_deref(),
is_quiet,
)?;
}

let schemes_repo_path = hooks_path.join(SCHEMES_REPO_NAME);
Expand All @@ -45,6 +63,7 @@ pub fn update(config_path: &Path, data_path: &Path, is_quiet: bool) -> Result<()
SCHEMES_REPO_NAME,
SCHEMES_REPO_URL,
&schemes_repo_path,
Some(SCHEMES_REPO_REVISION),
is_quiet,
)?;

Expand Down
Loading
Loading