feat: sync optional path argument #21

Merged
krauterbaquette merged 5 commits from sync-path-arg into main 2025-01-23 15:38:32 +00:00

Add an optional path argument to the sync command to specify which paths to sync.
It will default to everything.

Addressing Issue: #18

Add an optional `path` argument to the `sync` command to specify which paths to sync. It will default to `everything`. Addressing Issue: #18
added path argument to sync command
All checks were successful
Rust Checks / Run Rust Check (push) Successful in 2m50s
bca0957e6a
allows to control which paths to sync
it will default to all paths
fixed logging for path-specific syncing
All checks were successful
Rust Checks / Run Rust Check (push) Successful in 2m45s
205a84ffa0
now only the actually commited files will be shown in the status report.

also improved the logic of path specific syncing to also support files
Author
Owner

Test

A local repository is needed

The change log should always only display the files that were committed.

Sync without paths (no breaking changes)

$ echo "test" > new.txt
$ sac sync

new.txt should be committed.

Sync directory

$ mkdir folder
$ echo "test" > folder/new.txt
$ echo "change" > new.txt
$ sac sync -p folder

Only the changes inside folder/new.txt should be committed.

Sync file

$ mkdir files
$ echo "test" > files/new.txt
$ echo "more change" > new.txt
$ sac sync -p new.txt

Only the changes inside new.txt should be committed.

Sync (from subdir)

$ mkdir subdir
$ echo "even more change" > new.txt
$ cd subdir
$ echo "test" > new.txt
$ sac sync -p new.txt

Only the changes inside subdir/new.txt should be committed.

Sync (parent from subdir)

$ mkdir has-parent
$ echo "test" > parent.txt
$ cd has-parent
$ sac sync ../parent.txt

Only the changes inside parent.txt should be committed.

# Test > A local repository is needed > > The _change log_ should always only display the files that were committed. ## Sync without paths (no breaking changes) ```console $ echo "test" > new.txt $ sac sync ``` `new.txt` should be committed. ## Sync directory ```console $ mkdir folder $ echo "test" > folder/new.txt $ echo "change" > new.txt $ sac sync -p folder ``` Only the changes inside `folder/new.txt` should be committed. ## Sync file ```console $ mkdir files $ echo "test" > files/new.txt $ echo "more change" > new.txt $ sac sync -p new.txt ``` Only the changes inside `new.txt` should be committed. ## Sync (from subdir) ```console $ mkdir subdir $ echo "even more change" > new.txt $ cd subdir $ echo "test" > new.txt $ sac sync -p new.txt ``` Only the changes inside `subdir/new.txt` should be committed. ## Sync (parent from subdir) ```console $ mkdir has-parent $ echo "test" > parent.txt $ cd has-parent $ sac sync ../parent.txt ``` Only the changes inside `parent.txt` should be committed.
improved rebase error message
All checks were successful
Rust Checks / Run Rust Check (push) Successful in 2m53s
92bdf7fb2f
when rebasing and excluding unresolved merge conflicts with the --path argument, a better error will now be displayed
krauterbaquette changed title from WIP: feat: sync optional path argument to feat: sync optional path argument 2025-01-02 23:59:52 +00:00
krauterbaquette changed title from feat: sync optional path argument to WIP: feat: sync optional path argument 2025-01-02 23:59:56 +00:00
krauterbaquette changed title from WIP: feat: sync optional path argument to feat: sync optional path argument 2025-01-02 23:59:59 +00:00
aviac approved these changes 2025-01-11 16:27:36 +00:00
Dismissed
aviac left a comment
Contributor

Nur ein paar Kleinigkeiten

Nur ein paar Kleinigkeiten
@ -36,6 +36,10 @@ pub struct Cmd {
#[arg(long, default_value = "false")]
/// this will ignore checks for unresolved merge conflicts
allow_unresolved: bool,
#[arg(short, long)]
/// specifing a path will only sync the given path
path: Option<String>,
Contributor

Ich glaube man kann irgendwie auch hier gleich in clap schon PathBufs expecten. Dann macht es sogar ein paar extra checks beim parsen wenn ich mich recht erinnere und du sparst dir die conversion später

Ich glaube man kann irgendwie auch hier gleich in clap schon PathBufs expecten. Dann macht es sogar ein paar extra checks beim parsen wenn ich mich recht erinnere und du sparst dir die conversion später
krauterbaquette marked this conversation as resolved
@ -68,19 +71,23 @@ mod commit {
pub fn save_changes(
repo: &Repository,
commit_message: &str,
path: &Option<String>,
allow_unresolved: bool,
) -> anyhow::Result<()> {
let status = git_status::StatusReport::new(&repo)?;
let status = git_status::StatusReport::new(&repo, &path)?;
// error out when there are merge conflicts
if !allow_unresolved {
status.assume_no_conflicts()?;
}
let cwd = git_root()?;
let path = match path {
Contributor

Geschmackssache: Das kann man kürzer schreiben als path.unrwap_or("."). Wahrscheinlich geht es nicht, weil die types nicht ganz passen und es wäre vorerst pain das zu fixen. Deswegen lass es ruhig. Will dir nur mal die Funktionalitäten der std lib langsam zeigen

Geschmackssache: Das kann man kürzer schreiben als `path.unrwap_or(".")`. Wahrscheinlich geht es nicht, weil die types nicht ganz passen und es wäre vorerst pain das zu fixen. Deswegen lass es ruhig. Will dir nur mal die Funktionalitäten der `std` lib langsam zeigen
Author
Owner

Sollte verbessert sein in diesem commit

Sollte verbessert sein in [diesem commit](https://git.solarpunk.social/GTA-HEG/SAC/commit/10e114e2c370fcc362c8bcf9b9556e7851f7da17)
krauterbaquette marked this conversation as resolved
shortend syntax for using default value
All checks were successful
Rust Checks / Run Rust Check (push) Successful in 3m7s
10e114e2c3
adressing comment: GTA-HEG/SAC#21 (comment)
switched to PathBuf path argument
All checks were successful
Rust Checks / Run Rust Check (push) Successful in 3m6s
e34be32e69
clap will perform checks, that given input is actually a path
-> improved error handeling

later conversion to PathBuf no longer needed
aviac approved these changes 2025-01-23 10:50:23 +00:00
aviac left a comment
Contributor

Sieht gut aus! :)

Sieht gut aus! :)
krauterbaquette deleted branch sync-path-arg 2025-01-23 15:38:33 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
krauterbaquette/sac!21
No description provided.