libgit2 how to do a commit of all files added_by_path - libgit2

I want to imitate this behaviour in libgit:
create files: touch {1..100}
git add .
git commit -a -e
For every file I create, I do the following:
do {
git_index_read()
git_index_add_bypath()
git_index_write()
git_commit_create() <--want this to be delayed after all files are created.
} while (0)
The above ops, the files get added and are shown in git log output.
What I would like to achieve:
do {
git_index_read()
git_index_add_bypath()
git_index_write()
} while (0)
git_commit_create() <--want this to be delayed after all files are created.
If I delay git_commit_create till end of all creates, none of the files get added in the commit. But git status -s does show these staged files.

Related

Vercel ignore build step according to folder of committed files

i'm using vercel's ignore build step field to disable preview deploys (IE - only deploy if the branch is main)
I'm doing this with the following bash script:
if [[ "$VERCEL_GIT_COMMIT_REF" == "main" ]] ; then
# Proceed with the build
echo "✅ - Build can proceed"
exit 1;
else
# Don't build
echo "🛑 - Build canceled"
exit 0;
fi
Now, another requirement I have is to only deploy if the changed files belong to a specific folder. Can I somehow combine these two requirements in the same script?
How do I access the paths of the committed files in this bash script?
Thanks!
Vercel has added some docs that address this exact situation:
git diff HEAD^ HEAD --quiet ./packages/frontend/
If changes were commited to ./packages/frontend/, the command will yield a non-empty response, allowing the build to proceed.
I also use a similar setup, but call a node script (check it out here) as my Ignored Build Step option.

ignore all changes to dir

We have a git submodule, it's in a folder called 'config' in several repos.
I am getting this when doing a merge:
On branch oleg/feature/1537299444
Your branch is up to date with 'origin/oleg/feature/1537299444'.
Changes not staged for commit:
modified: config (modified content)
no changes added to commit
and it exits with 1.
How can I ignore all changes to the 'config' folder, which is a gitsubmodule?
I tried:
git checkout config
but that didn't do anything
Try first to check what kind of of diff/new element you see in the submodule.
cd config
git status
git diff
If you can, do a git reset --hard in that config folder (if you don't need any local modification done in config)
Then go back to the parent repo, and retry your git merge.

trying to push file into bitbucket repo, but showing wrong repo

Normally I open a bash prompt inside my Test folder. I then git add, commit, and push origin the file and it goes into my Test folder in bitbucket. Now somehow my Test folder instead of showing .../Test (Development), it shows another repo, .../Test (Review). I do not know why it changed. How can I get (Review) to be (Development)?
In git there are pretty much three stages. When pressing git status you probably get a similar few to this with many more files:
# On branch review
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: file.txt
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file2.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3.txt
file.txt on top has staged changes. These will go into the next commit when you do git commit.
file2.txt has unstaged changes. This file is tracked in the repository but the changes will not be added to the next commit. Only if you git add this file will it get staged.
file3.txt is an untracked file. You have to add it with git add which will automatically put it into the staged area. Next time you will make changes to it you will find it in the unstaged area like file2.txt
from this situation git checkout master gives:
error: Your local changes to the following files would be overwritten by checkout:
file2.txt
Please, commit your changes or stash them before you can switch branches.
Aborting
This is probably what you get too. Git noticed that you made changes in the tracked file file2.txt but you didn't specify what to do with them. Similarly I suspect that you made changed to those '50 or so files' and now git doesn't know what to do.
Either add them to your commit and do a commit:
git add <files>
git commit -m "did some work"
or drop the changes:
git checkout <files>
Then they will return to the way they were at the last commit.
You can also add some files and drop others, or even do partial adds with git add -p.
Check the changes you made with git diff.
After this is resolved you can switch branches again with git checkout <branchname>.
Without more information on your branch structure in your bitbucket and your commit history it is hard to say what you can push to where.

Enabling git log parameters by default

I like the way that the following command prints out git logs:
git log --oneline --decorate --graph
I would like to make that the default format whenever I use git log. Is there a way to edit ~/.gitconfig to enable oneline, decorate, and graph by default?
And yes, I'm aware that I can alias those options to another git command alias, but I'd rather that log just print out using those options by default.
Git allows you to activate --oneline and --decorate by default for log, show, etc.:
git config --global format.pretty oneline
git config --global log.decorate short
However, as of v2.1.0 v2.2.2, Git does not allow you to activate --graph by default. One way around that (adapted from this SuperUser answer) is to define the following function in your .<shell>rc file:
git() {
if [ "$1" = "log" ]
then
command git log --graph "${#:2}";
else
command git "$#";
fi;
}
One caveat (pointed out by hvd in his comment): if you specify options between git and log, as in
git -c log.showroot=false log -p
then, because the first argument is -c and not log, the --oneline --decorate --graph flags won't be used.

Forcedly update workspace in Accurev

Is there any command to update my workspace forcedly in Accurev, directly replace the local files with the backed files, and don't care about the conflict files, modified files and so on?
I really miss the cvs command cvs update -C -d
According to question, I have similar issues. Usually I just use following commands:
accurev update -9
accurev pop -O -R .
accurev update
No, you will need to run a few operations. You can create a script to force update your workspace.
Basically, you will generate a list of all the modified, kept, overlap, member files, then purge those files, then update your workspace.
Check out the stat section in the CLI manual.
What You can do is delete all the local files from the file system and then do a:
accurev pop -R <path to local workspace directory>
I had similar issue; First take a back up of existing workspace, then Delete all the files in the local work-space folder. Click update button on Accurev. All files will be re-loaded on the workspace.
If you just want to undo all changes you have done in the workspace:
accurev stat -R -m -fl . | xargs -n 1 accurev purge
You can use similar command with rm / accurev pop to force refetch from backend. You can also vary the flags, -m for modified, -k for kept, -a for all.