Skip to content

Commit

Permalink
Rename revision to rev
Browse files Browse the repository at this point in the history
This affects both the command line option as well as the config file.
  • Loading branch information
rossmacarthur committed Apr 27, 2020
1 parent 140d171 commit 92bb588
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ git = "https://github.com/sindresorhus/pure"

#### Specifying a branch, tag, or commit

All Git sources also allow setting of one of the `branch`, `tag` or `revision`
All Git sources also allow setting of one of the `branch`, `tag` or `rev`
fields. **sheldon** will then checkout the repository at this reference.

```toml
Expand Down
3 changes: 1 addition & 2 deletions docs/plugins.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ prompt = { value = 'ln -sf "{{ filename }}" "{{ root }}/functions/prompt_{{ name
[plugins.async]
# `github` sources provide the repository in the form {username}/{repository}.
github = "mafredri/zsh-async"
# `github', `git`, or `gist` sources may provide a `branch`, `tag`, or
# `revision` field.
# `github', `git`, or `gist` sources may provide a `branch`, `tag`, or `rev`.
tag = "v1.7.1"
# All plugins can specify the template names that will be applied.
apply = ["function"]
Expand Down
24 changes: 12 additions & 12 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ struct Add {
)]
branch: Option<String>,

/// Checkout a specific revision.
/// Checkout a specific commit.
#[structopt(long, value_name = "SHA", group = "git-reference")]
revision: Option<String>,
rev: Option<String>,

/// Checkout a specific tag.
#[structopt(long, value_name = "TAG", group = "git-reference")]
Expand Down Expand Up @@ -212,16 +212,16 @@ impl Plugin {
local,
protocol,
branch,
revision,
rev,
tag,
directory,
uses,
apply,
} = add;

let reference = match (branch, revision, tag) {
let reference = match (branch, rev, tag) {
(Some(s), None, None) => Some(GitReference::Branch(s)),
(None, Some(s), None) => Some(GitReference::Revision(s)),
(None, Some(s), None) => Some(GitReference::Rev(s)),
(None, None, Some(s)) => Some(GitReference::Tag(s)),
(None, None, None) => None,
// this is unreachable because these three options are in the same mutually exclusive
Expand Down Expand Up @@ -522,7 +522,7 @@ OPTIONS:
--local <DIR> Add a local directory
--protocol <PROTO> The Git protocol for a Gist or GitHub plugin
--branch <BRANCH> Checkout the tip of a branch
--revision <SHA> Checkout a specific revision
--rev <SHA> Checkout a specific commit
--tag <TAG> Checkout a specific tag
--directory <PATH> Which sub directory to use in this plugin
--use <MATCH>... Which files to use in this plugin
Expand Down Expand Up @@ -556,7 +556,7 @@ ARGS:
"test",
"--git",
"https://github.com/rossmacarthur/sheldon-test",
"--revision",
"--rev",
"ad149784a1538291f2477fb774eeeed4f4d29e45",
"--directory",
"missing",
Expand All @@ -581,7 +581,7 @@ ARGS:
local: None,
protocol: None,
branch: None,
revision: Some("ad149784a1538291f2477fb774eeeed4f4d29e45".into()),
rev: Some("ad149784a1538291f2477fb774eeeed4f4d29e45".into()),
tag: None,
directory: Some("missing".into()),
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
Expand Down Expand Up @@ -622,7 +622,7 @@ ARGS:
local: None,
protocol: Some("ssh".parse().unwrap()),
branch: None,
revision: None,
rev: None,
tag: Some("0.1.0".into()),
directory: Some("missing".into()),
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
Expand Down Expand Up @@ -663,7 +663,7 @@ ARGS:
local: None,
protocol: Some("https".parse().unwrap()),
branch: Some("feature".into()),
revision: None,
rev: None,
tag: None,
directory: Some("missing".into()),
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
Expand Down Expand Up @@ -698,7 +698,7 @@ ARGS:
local: None,
protocol: None,
branch: None,
revision: None,
rev: None,
tag: None,
directory: None,
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
Expand Down Expand Up @@ -733,7 +733,7 @@ ARGS:
local: Some("~/.dotfiles/zsh/pure".into()),
protocol: None,
branch: None,
revision: None,
rev: None,
tag: None,
directory: None,
uses: Some(vec_into!["{name}.sh", "*.zsh"]),
Expand Down
19 changes: 8 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum GitReference {
/// From the tip of a branch.
Branch(String),
/// From a specific revision.
Revision(String),
Rev(String),
/// From a tag.
Tag(String),
}
Expand Down Expand Up @@ -584,8 +584,8 @@ impl RawPlugin {
TempSource::External(source) => {
if !source.is_git() && is_reference_some {
bail!(
"the `branch`, `tag`, and `revision` fields are not supported by this \
plugin type"
"the `branch`, `tag`, and `rev` fields are not supported by this plugin \
type"
);
} else if protocol.is_some() && !is_gist_or_github {
bail!("the `protocol` field is not supported by this plugin type");
Expand All @@ -604,10 +604,7 @@ impl RawPlugin {
TempSource::Inline(raw) => {
let unsupported = [
("`protocol` field is", protocol.is_some()),
(
"`branch`, `tag`, and `revision` fields are",
is_reference_some,
),
("`branch`, `tag`, and `rev` fields are", is_reference_some),
("`directory` field is", directory.is_some()),
("`use` field is", uses.is_some()),
("`apply` field is", apply.is_some()),
Expand Down Expand Up @@ -786,9 +783,9 @@ mod tests {
}

#[test]
fn git_reference_deserialize_revision() {
let test: TestGitReference = toml::from_str("revision = 'cd65e828'").unwrap();
assert_eq!(test.g, GitReference::Revision(String::from("cd65e828")));
fn git_reference_deserialize_rev() {
let test: TestGitReference = toml::from_str("rev = 'cd65e828'").unwrap();
assert_eq!(test.g, GitReference::Rev(String::from("cd65e828")));
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -1129,7 +1126,7 @@ mod tests {
.unwrap_err();
assert_eq!(
error.to_string(),
"the `branch`, `tag`, and `revision` fields are not supported by this plugin type"
"the `branch`, `tag`, and `rev` fields are not supported by this plugin type"
);
}

Expand Down
16 changes: 8 additions & 8 deletions src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub struct LockedConfig {
impl fmt::Display for GitReference {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Branch(s) | Self::Revision(s) | Self::Tag(s) => write!(f, "{}", s),
Self::Branch(s) | Self::Rev(s) | Self::Tag(s) => write!(f, "{}", s),
}
}
}
Expand All @@ -138,7 +138,7 @@ impl GitReference {
fn lock(&self, repo: &git2::Repository) -> Result<LockedGitReference> {
match self {
Self::Branch(s) => git::resolve_branch(repo, s),
Self::Revision(s) => git::resolve_revision(repo, s),
Self::Rev(s) => git::resolve_rev(repo, s),
Self::Tag(s) => git::resolve_tag(repo, s),
}
.map(LockedGitReference)
Expand Down Expand Up @@ -830,7 +830,7 @@ mod tests {
"feature"
);
assert_eq!(
GitReference::Revision("ad149784a".to_string()).to_string(),
GitReference::Rev("ad149784a".to_string()).to_string(),
"ad149784a"
);
assert_eq!(GitReference::Tag("0.2.3".to_string()).to_string(), "0.2.3");
Expand All @@ -854,18 +854,18 @@ mod tests {
}

#[test]
fn git_reference_lock_revision() {
fn git_reference_lock_rev() {
let temp = tempfile::tempdir().expect("create temporary directory");
let repo = git_clone_sheldon_test(&temp);

let reference = GitReference::Revision("ad149784a".to_string());
let reference = GitReference::Rev("ad149784a".to_string());
let locked = reference.lock(&repo).unwrap();
assert_eq!(
locked.0.to_string(),
"ad149784a1538291f2477fb774eeeed4f4d29e45"
);

let reference = GitReference::Revision("2c4ed7710".to_string());
let reference = GitReference::Rev("2c4ed7710".to_string());
let error = reference.lock(&repo).unwrap_err();
assert_eq!(error.to_string(), "failed to find revision `2c4ed7710`");
}
Expand Down Expand Up @@ -963,7 +963,7 @@ mod tests {
&create_test_context(directory),
directory.to_path_buf(),
Url::parse("https://github.com/rossmacarthur/sheldon-test").unwrap(),
Some(GitReference::Revision(
Some(GitReference::Rev(
"ad149784a1538291f2477fb774eeeed4f4d29e45".to_string(),
)),
)
Expand All @@ -988,7 +988,7 @@ mod tests {
&create_test_context(directory),
directory.to_path_buf(),
Url::parse("git://github.com/rossmacarthur/sheldon-test").unwrap(),
Some(GitReference::Revision(
Some(GitReference::Rev(
"ad149784a1538291f2477fb774eeeed4f4d29e45".to_string(),
)),
)
Expand Down
6 changes: 3 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ pub mod git {
}

/// Resolve a revision to a object identifier.
pub fn resolve_revision(repo: &Repository, revision: &str) -> anyhow::Result<Oid> {
pub fn resolve_rev(repo: &Repository, rev: &str) -> anyhow::Result<Oid> {
let obj = repo
.revparse_single(revision)
.with_context(s!("failed to find revision `{}`", revision))?;
.revparse_single(rev)
.with_context(s!("failed to find revision `{}`", rev))?;
Ok(match obj.as_tag() {
Some(tag) => tag.target_id(),
None => obj.id(),
Expand Down

0 comments on commit 92bb588

Please sign in to comment.