Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed skip-git and added how to for git ops #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- [User's Guide](./how-to/index.md)
- [How to Compile Xvc](./how-to/compile.md)
- [Xvc with Git Branches](./how-to/git-branches.md)
- [Turn off Git Integration](./how-to/turn-off-git-automation.md)

- [Command Reference](./ref/xvc.md)
- [`xvc init`](./ref/xvc-init.md)
Expand Down
121 changes: 121 additions & 0 deletions book/src/how-to/turn-off-git-automation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Turning off Automated Git Operations

By default Xvc automates all common git operations. When you run an Xvc operation that affects the files under `.xvc` directory, the changes are committed to the repository automatically.

Git autmation runs in Git repositories.

```console
$ git init
Initialized empty Git repository in [CWD]/.git/

$ xvc init
```

We'll show these examples in the following directory tree.

```console
$ xvc-test-helper create-directory-tree --directories 1 --files 3 --seed 20231012
$ tree
.
└── dir-0001
├── file-0001.bin
├── file-0002.bin
└── file-0003.bin

2 directories, 3 files

```

When you begin to track a file in the repository, Xvc adds the file to .gitignore in the directory the file is found.

```console
$ xvc file track dir-0001/file-0001.bin

$ zsh -cl 'cat dir-0001/.gitignore'
### Following 1 lines are added by xvc on [..]
/file-0001.bin

```

Xvc also adds a commit for all the changes caused by the command.

```console
$ git log -n 1
commit [..]
Author: [..]
Date: [..]

Xvc auto-commit after '[..]xvc file track dir-0001/file-0001.bin'

```

The commit message includes the command you gave to run to find the exact change in history.

If you don't track a file with Xvc, they are not added to `.gitignore` and you can see them with `git status`.

```console
$ git status -s
?? dir-0001/file-0002.bin
?? dir-0001/file-0003.bin

```
If you want to skip this automated Git operations, you can add `--skip-git` flag to commands.

```console
$ xvc --skip-git file track dir-0001/file-0002.bin

$ git status -s
M dir-0001/.gitignore
?? .xvc/ec/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? dir-0001/file-0003.bin

```

Note that, `--skip-git` flag doesn't affect the files to be added to `.gitignore` files.

```console
$ zsh -cl 'cat dir-0001/.gitignore'
### Following 1 lines are added by xvc on [..]
/file-0001.bin
### Following 1 lines are added by xvc on [..]
/file-0002.bin

```

You can use usual Git workflow to add and commit the files.

```
$ git add .xvc dir-0001/.gitignore
$ git commit -m "Began to track dir-0001/file-0002.bin with Xvc"
[main [..]] Began to track dir-0001/file-0002.bin with Xvc
7 files changed, 8 insertions(+)
create mode 100644 .xvc/ec/[..]
create mode 100644 .xvc/store/[..].json
create mode 100644 .xvc/store/[..].json
create mode 100644 .xvc/store/[..].json
create mode 100644 .xvc/store/[..].json
create mode 100644 .xvc/store/[..].json

```

If you never want Xvc to handle commits, you can set `git.use_git` option in
`.xvc/config` file to false or set `XVC_git.use_git=false` in the environment.

```console
$ XVC_git.use_git=false xvc file track dir-0001/file-0003.bin

$ git status -s
M dir-0001/.gitignore
?? .xvc/ec/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]
?? .xvc/store/[..]

```
18 changes: 10 additions & 8 deletions lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,17 @@ pub fn dispatch(cli_opts: cli::XvcCLI) -> Result<()> {
match xvc_root_opt {
Some(xvc_root) => {
watch!(&cli_opts.command_string);
handle_git_automation(
&output_snd,
xvc_root,
cli_opts.to_branch.as_deref(),
&cli_opts.command_string,
)?;
if cli_opts.skip_git {
debug!(output_snd, "Skipping Git operations");
} else {
handle_git_automation(
&output_snd,
xvc_root,
cli_opts.to_branch.as_deref(),
&cli_opts.command_string,
)?;
}
}

None => {
debug!(
output_snd,
Expand Down Expand Up @@ -578,7 +581,6 @@ fn git_auto_commit(
],
) {
Ok(git_add_output) => {

watch!(git_add_output);
if git_add_output.trim().len() == 0 {
debug!(output_snd, "No files to commit");
Expand Down