Skip to content

Commit f59e4f5

Browse files
committed
Merge branch 'dev'
2 parents ab1c260 + 8b39a8b commit f59e4f5

File tree

8 files changed

+89
-119
lines changed

8 files changed

+89
-119
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "git-credential-github"
33
authors = ["ldev <ldev at ldev dot eu dot org>"]
4-
version = "2.0.0"
4+
version = "2.1.0"
55
license-file="LICENSE.md"
66
edition = "2021"
77
description="A simple git credentials helper for github"
@@ -10,10 +10,11 @@ description="A simple git credentials helper for github"
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[dependencies]
13-
clap = {version = "4.3", features = ["default", "cargo", "derive"]}
13+
clap = {version = "4.4", features = ["default", "cargo", "derive"]}
1414
reqwest = {version = "0.11", features= ["json"]}
1515
serde = {version="1.0", features=["derive"]}
1616
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
17-
shlex = {version= "1.1.0"}
17+
shlex = {version= "1.2.0"}
1818
log = {version="0.4"}
19+
thiserror={version="1.0.50"}
1920
stderrlog = {version="0.5"}

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This sets the credential helper for github using the cache helper with a timeout
3131
### Set only for repos owned by you
3232
```~/.gitconfig```
3333
```ini
34-
[credentials]
34+
[credential]
3535
useHttpPath = true
3636
[credential "https://github.com/Xgames123"] # change to your name
3737
username=Xgames123 # change to your name
@@ -52,3 +52,8 @@ If you find a bug, get an error or the docs are wrong.
5252
* [Create an issue](https://github.com/Xgames123/git-credential-github/issues/new/)
5353
* Message me <[[email protected]](mailto://[email protected])>
5454
* Message me on discord [ldev105](https://ldev.eu.org/socials/discord)
55+
56+
57+
# Building debian packages from source
58+
1. install [reltools](https://github.com/Xgames123/reltools)
59+
2. run makepkg_deb inside the packaging directory

TODO_RELEASE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
1. bump versions: Cargo.toml, packaging/PKGBUILD
2+
4. merge with main
3+
5. tag commit and create release
4+
5+
6. bump aur/PKGBUILD
6+
7. makepkg_deb.sh
7+
8. regen checksums (aur/PKGBUILD) and .SRCINFO
8+
9. close issues fixed in release

packaging/PKGBUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pkgver=2.0.0
1+
pkgver=2.1.0
22
pkgrel=1
33

44
pkgname=git-credential-github

packaging/makepkg_deb.sh

Lines changed: 0 additions & 102 deletions
This file was deleted.

src/credhelper.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use std::collections::HashMap;
22
use std::io;
33
use std::process::{Child, Command, Stdio};
4+
use thiserror::Error;
45

5-
use log::debug;
6+
use log::{debug, error};
67

78
use crate::{paramparsing, Operation};
89

@@ -27,11 +28,19 @@ fn spawn_helper(helper: &str, operation: Operation) -> io::Result<Child> {
2728
Ok(cmd.spawn()?)
2829
}
2930

31+
#[derive(Error, Debug)]
32+
pub enum CredHelperError {
33+
#[error("{0}")]
34+
Io(#[from] std::io::Error),
35+
#[error("credential helper exited with code {0}")]
36+
Non0ExitCode(i32, Option<HashMap<String, String>>),
37+
}
38+
3039
pub fn run(
3140
helper: &str,
3241
operation: Operation,
3342
params: &HashMap<String, String>,
34-
) -> io::Result<HashMap<String, String>> {
43+
) -> Result<HashMap<String, String>, CredHelperError> {
3544
let mut process = spawn_helper(helper, operation)?;
3645
let mut stdin = process.stdin.take().unwrap();
3746
paramparsing::write_to(&params, &mut stdin)?;
@@ -40,6 +49,14 @@ pub fn run(
4049
let mut stdout = process.stdout.take().unwrap();
4150
let output_params = paramparsing::parse_from(&mut stdout)?;
4251
drop(stdout);
43-
process.wait()?;
44-
Ok(output_params)
52+
let output = process.wait()?;
53+
54+
if !output.success() {
55+
Err(CredHelperError::Non0ExitCode(
56+
output.code().unwrap_or_default(),
57+
Some(output_params),
58+
))
59+
} else {
60+
Ok(output_params)
61+
}
4562
}

src/main.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ struct Cli {
4040
#[arg(long)]
4141
no_clip: bool,
4242

43+
/// Go through the authentication process even if not needed. (only for get operation)
44+
#[arg(long)]
45+
auth: bool,
46+
47+
/// Don't authenticate when the credential helper returns a non 0 exit code
48+
#[arg(long)]
49+
no_auth_on_fail: bool,
50+
4351
#[command(subcommand)]
4452
operation: Operation,
4553
}
@@ -100,16 +108,29 @@ async fn main() {
100108
}
101109

102110
let mut output =
103-
credhelper::run(&backing_helper, cli.operation, &params).unwrap_or_else(|err| {
104-
die!(
105-
"Failed to run credential helper '{}'\n{}",
106-
backing_helper,
107-
err
108-
);
111+
credhelper::run(&backing_helper, cli.operation, &params).unwrap_or_else(|err| match err {
112+
credhelper::CredHelperError::Io(err) => {
113+
die!(
114+
"Failed to run credential helper '{}'\n{}",
115+
backing_helper,
116+
err
117+
);
118+
}
119+
credhelper::CredHelperError::Non0ExitCode(code, output) => {
120+
error!(
121+
"Credential helper '{}' exited with code: {}",
122+
backing_helper, code
123+
);
124+
if cli.no_auth_on_fail {
125+
die!("See Last error");
126+
}
127+
128+
output.unwrap_or_default()
129+
}
109130
});
110131

111-
if cli.operation.is_get() && !output.contains_key("password") {
112-
debug!("No password returned by helper. Fetching credentials..");
132+
if cli.operation.is_get() && (!output.contains_key("password") || cli.auth) {
133+
debug!("Fetching credentials..");
113134
let client = Client::new();
114135
let device_code = ghauth::get_device_code(&client).await.unwrap();
115136

verify.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# script to verify versions
2+
3+
cargo_ver=$(rg -or "\$1" "^version[\t ]*=[\t ]*\"([0-9]\.[0-9]\.[0-9])\"" Cargo.toml)
4+
echo "version: $cargo_ver"
5+
pkg_ver=$(rg -or "\$1" "^pkgver=[\t ]*([0-9]\.[0-9]\.[0-9])" packaging/PKGBUILD)
6+
7+
git_ver=$(git tag | tail -n 1)
8+
9+
10+
if [ "$cargo_ver" != "$pkg_ver" ] ; then
11+
echo "PKGBUILD version '$pkg_ver' doesn't match $cargo_ver"
12+
exit -1
13+
fi
14+
15+
if [ "$git_ver" != "$cargo_ver" ] ; then
16+
echo "git tag '$git_ver' doesn't match version $cargo_ver"
17+
exit -1
18+
fi
19+
20+
echo "ALL CHECKS OK"

0 commit comments

Comments
 (0)