Skip to content

Commit

Permalink
Fix commit error
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrav committed Apr 3, 2023
1 parent abb40ea commit 5953cc2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2023-04-03

This release marks the first full realization of project's description.

### Fixed

- Fix git commit error

## [0.0.3] - 2023-04-03

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

- 'None

[0.1.0]: https://github.com/mbrav/git_raider/compare/0.0.3...0.1.0
[0.0.3]: https://github.com/mbrav/git_raider/compare/0.0.2...0.0.3
[0.0.2]: https://github.com/mbrav/git_raider/compare/0.0.1...0.0.2
[0.0.1]: https://github.com/mbrav/git_raider/releases/tag/0.0.1
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "git_raider"
version = "0.0.3"
version = "0.1.0"
descripion = "Mass git repository search, replace and commit tool"
authors = ["mbrav <[email protected]>"]
edition = "2021"
Expand Down
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,27 @@ This cli tool is designed to **recursively** run through a directory (`-p`/`--pa
* A regex pattern specified with the `-r`/`--replace` flag that will replace content selected with `-s`/`--select` flag;
* A commit message specified with the `-m`/`--message`. If this flag is not passed, no commit will be made.

## Example

```bash
cargo run -- \
-p "/home/user/git_repos" \
-b "development\$" \
-f "values.yaml|config.env" \
-l "prod-kafka.local:9092" \
-s "prod-kafka" \
-r "dev-kafka" \
-m "Change Apache Kafka server url from 'prod-kafka' to 'dev-kafka'" \
-d
```

### TODO

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

* Create new commit with specified message;
* Make `dry-run` much better;
* ~~Create new commit with specified message~~;
* Push changes to remote after successful commit;
* Make `dry-run` mode more functional.

## Run

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

You will get the following result:
You will get the following result showing you a help dialogue:

```text
Mass git repository search, replace and commit tool
Expand Down
22 changes: 13 additions & 9 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ pub fn stage_all(repo: &mut Repository) -> Result<(), git2::Error> {
Ok(())
}

/// Commit stages changes
/// TODO: Fix `{ code: -15, klass: 11, message: "failed to create commit: current tip is not the first parent" }'`
/// Commit staged changes
pub fn commit(repo: &mut Repository, msg: &str) -> Result<(), git2::Error> {
let signature = repo.signature().expect("Error getting repo's signature");
let oid = repo
.index()
.expect("Error unwrapping repo index")
.write_tree()
.expect("Error unwrapping index tree");
let mut index = repo.index().expect("Error unwrapping repo index");
let oid = index.write_tree().expect("Error unwrapping index tree");
let signature = repo.signature().expect("Error getting user's signature");
let parent_commit = repo.head().unwrap().peel_to_commit().unwrap();
let tree = repo.find_tree(oid).expect("Error unwrapping tree");
repo.commit(Some("HEAD"), &signature, &signature, msg, &tree, &[])?;
repo.commit(
Some("HEAD"),
&signature,
&signature,
msg,
&tree,
&[&parent_commit],
)?;
Ok(())
}

0 comments on commit 5953cc2

Please sign in to comment.