Skip to content

Commit 5953cc2

Browse files
committed
Fix commit error
1 parent abb40ea commit 5953cc2

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ 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.0] - 2023-04-03
9+
10+
This release marks the first full realization of project's description.
11+
12+
### Fixed
13+
14+
- Fix git commit error
15+
816
## [0.0.3] - 2023-04-03
917

1018
### Added
@@ -32,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3240

3341
- 'None
3442

43+
[0.1.0]: https://github.com/mbrav/git_raider/compare/0.0.3...0.1.0
3544
[0.0.3]: https://github.com/mbrav/git_raider/compare/0.0.2...0.0.3
3645
[0.0.2]: https://github.com/mbrav/git_raider/compare/0.0.1...0.0.2
3746
[0.0.1]: https://github.com/mbrav/git_raider/releases/tag/0.0.1

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git_raider"
3-
version = "0.0.3"
3+
version = "0.1.0"
44
descripion = "Mass git repository search, replace and commit tool"
55
authors = ["mbrav <mbrav@protonmail.com>"]
66
edition = "2021"

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,27 @@ This cli tool is designed to **recursively** run through a directory (`-p`/`--pa
1616
* A regex pattern specified with the `-r`/`--replace` flag that will replace content selected with `-s`/`--select` flag;
1717
* A commit message specified with the `-m`/`--message`. If this flag is not passed, no commit will be made.
1818

19+
## Example
20+
21+
```bash
22+
cargo run -- \
23+
-p "/home/user/git_repos" \
24+
-b "development\$" \
25+
-f "values.yaml|config.env" \
26+
-l "prod-kafka.local:9092" \
27+
-s "prod-kafka" \
28+
-r "dev-kafka" \
29+
-m "Change Apache Kafka server url from 'prod-kafka' to 'dev-kafka'" \
30+
-d
31+
```
32+
1933
### TODO
2034

2135
For base functionality to be completed, the following must still be finished:
2236

23-
* Create new commit with specified message;
24-
* Make `dry-run` much better;
37+
* ~~Create new commit with specified message~~;
38+
* Push changes to remote after successful commit;
39+
* Make `dry-run` mode more functional.
2540

2641
## Run
2742

@@ -31,7 +46,7 @@ To run, first install Rust's tool chain. Then build:
3146
cargo run -- --help
3247
```
3348

34-
You will get the following result:
49+
You will get the following result showing you a help dialogue:
3550

3651
```text
3752
Mass git repository search, replace and commit tool

src/git.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,20 @@ pub fn stage_all(repo: &mut Repository) -> Result<(), git2::Error> {
6060
Ok(())
6161
}
6262

63-
/// Commit stages changes
64-
/// TODO: Fix `{ code: -15, klass: 11, message: "failed to create commit: current tip is not the first parent" }'`
63+
/// Commit staged changes
6564
pub fn commit(repo: &mut Repository, msg: &str) -> Result<(), git2::Error> {
66-
let signature = repo.signature().expect("Error getting repo's signature");
67-
let oid = repo
68-
.index()
69-
.expect("Error unwrapping repo index")
70-
.write_tree()
71-
.expect("Error unwrapping index tree");
65+
let mut index = repo.index().expect("Error unwrapping repo index");
66+
let oid = index.write_tree().expect("Error unwrapping index tree");
67+
let signature = repo.signature().expect("Error getting user's signature");
68+
let parent_commit = repo.head().unwrap().peel_to_commit().unwrap();
7269
let tree = repo.find_tree(oid).expect("Error unwrapping tree");
73-
repo.commit(Some("HEAD"), &signature, &signature, msg, &tree, &[])?;
70+
repo.commit(
71+
Some("HEAD"),
72+
&signature,
73+
&signature,
74+
msg,
75+
&tree,
76+
&[&parent_commit],
77+
)?;
7478
Ok(())
7579
}

0 commit comments

Comments
 (0)