Skip to content

Commit 8d53fe6

Browse files
feat: add --tag option as an alias of --branch
1 parent 7afd63f commit 8d53fe6

7 files changed

Lines changed: 41 additions & 15 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.13] - 2020-06-20
9+
10+
### Added
11+
12+
- add support for `--commit` to open a specific commit by [@rubenrua](https://github.com/rubenrua)
13+
- add alias `--tag` for `--branch` as they are the same from git host provider perspective
14+
815
## [0.1.12] - 2020-05-16
916

1017
### Changed

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CONTRIBUTING
22

3+
# Pull Request
4+
5+
Just do the changes, we'll discuss about it on the PR.
6+
37
## PUBLISHING
48

59
- [ ] Change the code you want to update.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gitweb"
3-
version = "0.1.12"
3+
version = "0.1.13"
44
authors = ["Yoann Fleury <yoann.fleury@yahoo.com>"]
55
edition = "2018"
66
description = "Open the current remote repository in your browser"

src/git.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ use git2::{Error, ErrorCode, Repository};
33

44
/// Get the current repository.
55
pub fn get_repo() -> Result<Repository, Error> {
6-
Repository::discover(".")
6+
const CURRENT_WORKING_DIRECTORY: &str = ".";
7+
8+
Repository::discover(CURRENT_WORKING_DIRECTORY)
79
}
810

11+
// Get the current branch or return master.
912
pub fn get_branch(repo: &Repository, logger: &Logger) -> String {
1013
let head = match repo.head() {
1114
Ok(head) => Some(head),

src/main.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ fn main() {
5959
}
6060
};
6161

62-
// Get the branch to show in the browser. If the option is given, then, the
63-
// value will be used, else, the current branch is given, or master if
64-
// something went wrong.
65-
let branch = match opt.branch {
66-
Some(branch) => branch,
67-
None => {
68-
logger.verbose_print("No branch given, getting current one");
69-
70-
git::get_branch(&repo, &logger)
62+
// Get the tag to show in the browser. If the option is given, then the value
63+
// will be used as it is an alias for branch.
64+
let reference = if let Some(tag) = opt.tag { tag } else {
65+
// Get the branch to show in the browser. If the option is given, then, the
66+
// value will be used, else, the current branch is given, or master if
67+
// something went wrong.
68+
match opt.branch {
69+
Some(branch) => branch,
70+
None => {
71+
logger.verbose_print("No branch given, getting current one");
72+
73+
git::get_branch(&repo, &logger)
74+
}
7175
}
7276
};
7377

@@ -105,11 +109,11 @@ fn main() {
105109
)
106110
} else {
107111
format!(
108-
"https://{domain}/{repository}/{path}/{branch}",
112+
"https://{domain}/{repository}/{path}/{reference}",
109113
domain = parts.0,
110114
path = if parts.0 == BITBUCKET_HOSTNAME {"src"} else {"tree"},
111115
repository = parts.1,
112-
branch = branch
116+
reference = reference
113117
)
114118
};
115119

src/options.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ use structopt::StructOpt;
66
// Rename all will use the name of the field
77
#[structopt(rename_all = "kebab-case")]
88
pub struct Opt {
9-
/// Set the branch
9+
/// Set the branch (alias for --tag)
1010
///
1111
/// By setting the branch, you can override the default behavior that will
1212
/// set the branch to the current one in the repository. If something went
1313
/// wrong with the current one, it will set the value to master.
1414
#[structopt(short, long)]
1515
pub branch: Option<String>,
1616

17+
/// Set the tag (alias for --branch).
18+
///
19+
/// By setting the tag, you can override the default behavior that will set
20+
/// the branch to the current one in the repository and will instead take
21+
/// the reference tag (or branch) given as parameter.
22+
#[structopt(short, long)]
23+
pub tag: Option<String>,
24+
1725
/// Set a commit
1826
///
1927
/// By setting a commit, you can override the default behavior that will

0 commit comments

Comments
 (0)