libgit2: How to merge and commit after fetch? - c

I've managed to fetch from the remote, and I'm running the code below to get the changes staged in the local master branch.
git_annotated_commit * fetchhead_commit;
git_annotated_commit_lookup(&fetchhead_commit,
repo,
oid
);
git_merge(repo,&fetchhead_commit,1,NULL,NULL);
So now if I use the git command line tool to commit I get an automatic merge commit comment and after I can see that the log is the same as from the remote. I'm trying to obtain the same with libgit but my efforts so far in trying to create a commit of the merge results in the remote history to be lost.
How should I do a "proper" commit of the merged changes in order to preserve the history from the remote?
EDIT: Got a little further by doing a fast forward, but still if there are local commits these are lost after the incoming merge. Local changes are not lost, but staged after the merge and have to be committed again.
You can see my code here: https://github.com/fintechneo/libgit2/blob/master/jsbuild/jslib.c
The merge is happening in the fetchead_foreach_cb function which again is called from jsgitpull
And for the record this hack does work in the web-browser if anyone wonders what the emscripten stuff is about.

Create the merge commit with git_commit_create. The merge commit should have two parents. One is the current HEAD commit. The second is the same annotated commit you merged in git_merge (e.g. the fetch head).

Related

Unable to run 'USING PERIODIC COMMIT' since last week on NEO4J

I have downloaded the Desktop Version of NEO4J on my MAC last week. (It's version 1.2.4)
Neo4j Browser version: 4.0.3
Neo4j Server version: 3.5.14 (enterprise)
Last week I was using the USING PERIODIC COMMIT command of loading in a CSV as seen below, this set up my relationships fine. However as of a couple of days ago, I tried to do the exact same command however now I get an error which is shown as Executing queries that use periodic commit in an open transaction is not possible. Please can someone explain to me what has gone wrong please?
query:
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM
"file:/Volumes/Twitter_Dataset/tweets.csv" AS csvLine
MATCH (tweet:Tweet {tweetID: csvLine.tweetID})
MATCH (user:User {username: csvLine.username})
MERGE (user)-[:POSTS]->(tweet);
The short answer:
Prefix your USING PERIODIC COMMIT queries with :auto
Changes were pushed out to provide more context here, so the error message now includes a link for more info about what's going on, as well as the :auto workaround above.
The long answer:
This is related to a recent feature improvement in the Neo4j Browser, which has a side effect with USING PERIODIC COMMIT operations, but there is a way around this, and a browser update was already pushed to provide more context with a clear workaround.
The latest round of Neo4j Browser updates include this change, which uses transactional functions instead of auto-committed transactions, giving queries through the browser automatic retry capability, and better ability to cope with member changes when hitting against a causal cluster.
The problem is that USING PERIODIC COMMIT needs to be run in an auto-committed transaction. This requires a means to switch whether we're using an auto-committed transaction or not.
You said you're using browser version 4.0.3. I believe that went out yesterday, and included with it changes providing details about what's going on and how to get this to work as normal. When encountering that error, you should now see a link with info on the :auto command, mentioning auto-committing transactions. Following the link should show an info card with:
The :auto command will send the Cypher query following it, in an auto committing transaction. In general this is not recommended because of the lack of support for auto retrying on leader switch errors in clusters.
Some query types do however need to be sent in auto-committing transactions, USING PERIODIC COMMIT is the most notable one.
An example is provided on the card for prefixing a USING PERIODIC COMMIT query with :auto to let it execute in an auto-committing transaction.

Git Database - Everyone Pushing to Same Branch in Different Files

Database team is implementing code changes, using Visual Studio SSDT database projects with Git source control. Everyone is pushing to main Release branch with code review (only 5 developers on the team). All the database coworkers are only allowed pushing to different files only (tables, sprocs, functions), etc. The way work is assigned, none of us push or work the same sql file. Eventually all good changes from Release (currently in Work) are merged into Master branch (Production Ready).
Code Review ---> Push to Release Branch (Currently in work during Sprint) ---> Merge to Master Production Ready Branch
(a) What are the negative consequences of utilizing this strategy in Git?
(b) For cleaner history, should everyone Rebase ReleasePublic Remote into ReleaseLocal, or conducting Pull? (Fetch/Merge), I would think Rebase is answer for cleaner history.
Note: I agree, it would be annoying only if we are working on the same file and pushing changes. Alternative Strategy to create different feature branches and then merge into main branch. We are refraining from this strategy since each developer has 10 dba admin related changes a day, creating many branches and merges is time consuming and cumbersome-
https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow
Devops
The bottom line is if it's working for you then it's working.
The purpose of the source control solution is to assist you in producing software.
Use this setup until it doesn't work and then adjust. (Please note that all 5 of the devs could start using feature branches, if they want/need, without interfering with the other team member's flow).
Having said that there are consequences of using a single branch. Here are two examples
Releasable main/release branch
One of them could be shown in a following scenario:
A release happens
A commit with a bug in file A is committed
A commit file B is committed
You want to release the changes made to file B\
Now you don't have a releasable snapshot of the repo
If the changes for file A were tested in a feature branch then master/release branch is in a releasable state more often.
Pull requests
Having feature branches allows to use Pull Requests (which is a layer on top of git) better - your code reviews may be get easier to enforce and track.

Merging Development Branch to Main: There were no changes to merge

My main branch has some files that have different codes from the same file of development branch. The development branch is the one that has the correct version of these files but when I am trying to merge it to main branch(target); I am getting a message saying
There was no changes to merge
How can I resolve that problem so that the main branch has the correct version of those files?
When merging files TFS doesn't just look at the differences between the two branches, but it also keeps track of whether you've ignored these changes in a previous merge attempt. When merging TFS offers you 3 options when there are conflicts:
Merge
Keep Source
Keep Target
When you pick Keep target or when you manually merge and deselect certain changes, TFS will mark these changes as "resolved" and will not offer them again when you try to merge in the future. This is called a "merge credit".
You can also create these issues using the commandline when using tf merge /discard which will tell TFS to ignore the changes in those files/changesets when considering merges.
There are two ways to force TFS to reconsider these changes:
Use force merge. On the commandline you can initiate a merge in which TFS will temporarily ignore it's records and will offer you every different file for merging. This can be a lot of work, but once done your merge history will be back in shape. To issue a force merge run tf merge $/Source/Folder/File $/Target/Folder/File /force /version:T This will almost certainly raise a merge conflict which you can resolve to get the right changes in the target branch.
Undo the previous merge using Rollback. If you've recently done the merge in which changesets have been discarded. Find it in the history, rightclick the changeset and pick Rollback and check in the code that has been undone. This will actually remove all of the changes in that changeset and will reset the "merge credits". Once this has been done you can redo the merge and do it right this time. This can also be done from the command line using tf rollback

Is it "ok" to commit to detached head after resolving conflicts when rebasing with TortoiseGit?

During a rebase, TortoiseGit gave me a list of conflicts to resolve. I did that and tried to commit, but then it complained that I was committing to a detached head. I was given the option to create another branch which I declined.
I've read somewhere that you don't normally want to commit to a detached head, but I read elsewhere that this is a normal part of the rebase operation. It appeared to work fine, and nothing seems to have been lost.
Did I do the right thing committing to a detached head in this case?
The rebase dialog has a commit button for this case - there is no need for a manual commit.
If you do a manual commit you create an additional commit in the history.

Git, robots and diverging branches

I am trying to use git as something it wasn't made for - a database. Please feel free to tell me that this is a stupid idea.
Setup
One branch (let's call it robot) is being updated automatically by a script on a daily basis. The data comes from some other publicly available database.
Initially the master branch is the same as the robot branch.
Some of the data in the publicly available database is wrong, so I'll make a commit to the master branch and correct the error.
When the script detects any changes on the public database in the future, it will add those to the robot branch as a new commit (there's one commit per file).
Keeping track of differences
Now, I've obviously lost the ability to do a fast forward merge if I've modified the same file. But I could still cherry pick the good changes in the robot branch and import them into the master branch. The problem is that this might get rather messy after a while, when almost all the files have diverged.
How can I keep track of the difference between the different branches in a systematic way?
It sounds like you're looking for the git rebase command. This command allows you to update changes you've made to your master branch on top of the new head of the robot branch:
git checkout master
git rebase robot
There may be conflicts, if the database has been updated with a change to something you've changed in master. You must resolve those conflicts manually.

Resources