I'm trying to make the following git commands using the JGit library:
git rebase -i HEAD~2
git commit --amend --reset-author --no-edit --date 2022-07-07T15:30:00.0000000+03:00
git rebase --continue
git commit --amend --reset-author --no-edit --date 2022-07-07T15:33:40.0000000+03:00
git rebase --continue
To do this, I have to switch to the branch I want and then run these commands.
This is what I'm trying to do:
File yourFile = new File("...\\.git");
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
repositoryBuilder.setMustExist(true);
repositoryBuilder.setGitDir(yourFile);
Repository repository = repositoryBuilder.build();
Git git = new Git(repository);
git.checkout().setName("main").call();
RebaseCommand.InteractiveHandler squashHandler = new RebaseCommand.InteractiveHandler() {
#Override
public void prepareSteps(List<RebaseTodoLine> steps) {
for (RebaseTodoLine step : steps.subList(1, steps.size())) {
try {
step.setAction(RebaseTodoLine.Action.SQUASH);
step.setShortMessage("");
} catch (IllegalTodoFileModification e) {
throw new RuntimeException("Couldn't squash commit " + step.getCommit().name(), e);
}
}
}
#Override
public String modifyCommitMessage(String commit) {
return commit;
}
};
git.rebase().runInteractively(squashHandler).setUpstream("HEAD~" + 1).call();
And then I don't know what to do and I'm not sure what started out right.
I think the next step should be something like this:
git.commit().setAmend(true).<anything else>
Please tell me how to execute the above git commands with JGit. I tried to find documentation that describes everything in a very clear language, like this
git command: git rebase -i HEAD~2
JGit code: git.rebase().runInteractively(squashHandler).setUpstream("HEAD~" + 2).call();
But I couldn't find anything like that, and reading the documentation, I almost shot myself :) Thanks
Related
I have a requirement where I have to Add - Commit - Push 3 newly created Files into our Git Repository using GitBash commands on Button Click in a Web Application.
I have tried the following but in vain:
{
string gitCommand = "git bash";
string gitAddArgument = #"add -A" ;
string gitCommitArgument = #"commit""explanations_of_changes"" ";
string gitPushArgument = #"push our_remote";
Process.Start(gitCommand, gitAddArgument );
Process.Start(gitCommand, gitCommitArgument );
Process.Start(gitCommand, gitPushArgument );
}
On Button Click I need to Call the Git Bash Commands, Commit the 3 Files and then Push to Master Origin.
You have a few errors within your Git commands..
To add all files use: git add -A Note the capital A
To commit all modified files with a message use: git commit -a -m "Your message here"
To push your changes to remote use git push
To make your C# code complete:
{
string gitCommand = "git";
string gitAddArgument = "add -A" ;
string commitMessage = "Your commit message";
string gitCommitArgument = String.Format("commit -a -m \"{0}\"", commitMessage);
string gitPushArgument = "push";
Process.Start(gitCommand, gitAddArgument); // Runs: git add -A
Process.Start(gitCommand, gitCommitArgument); // Runs: git commit -a -m "Your commit message"
Process.Start(gitCommand, gitPushArgument); // Runs: git push
}
Note
Make sure the program git is within your PATH variabele else you wont be able to use it this way. If it's not in your PATH, use the absolute path to the git executeable
For example on linux it would be: /usr/bin/git this should be the text for gitCommand
SBT is silently failing when it can't download a plugin via SSH from a Git repository.
This is the output of SBT when it's trying to download the repository:
[info] Updating ProjectRef(uri("ssh://git#repository.com/plugin.git"), "plugin")...
# (nothing after that line)
And it just terminates after that with no explanation. This is very likely a bug with SBT's downloading of plugins via SSH from a Git repository.
When downloading the plugin succeeds, this line is printed:
[info] Done updating.
So for some reason, SBT isn't stating what's wrong, even when executed like this:
sbt -Xdebug test
Here are the relevant configuration files:
# project/build-properties
sbt.version=1.1.5
# project/plugins.sbt
lazy val buildPlugin = RootProject(uri("ssh://git#repository.com/plugin.git"))
lazy val root = (project in file(".")).dependsOn(buildPlugin)
Questions:
1. How can I get SBT to print more debugging information?
2. Where in the SBT code could I fix this bug?
3. How can I build and use my own version of SBT?
How can I get SBT to print more debugging information?
Using the latest launching script available from https://www.scala-sbt.org/download.html (1.2.1 as of August, 2018), you can run:
$ sbt -debug
Where in the SBT code could I fix this bug?
See my answer here https://github.com/sbt/sbt/issues/1120#issuecomment-415553592:
Here are some of the relevant code:
Load.builtinLoader - https://github.com/sbt/sbt/blob/v1.2.1/main/src/main/scala/sbt/internal/Load.scala#L480-L488
RetrieveUnit - https://github.com/sbt/sbt/blob/v1.2.1/main/src/main/scala/sbt/internal/RetrieveUnit.scala
Resolvers.git - https://github.com/sbt/sbt/blob/v1.2.1/main/src/main/scala/sbt/Resolvers.scala#L82-L101
Resolvers.creates - https://github.com/sbt/sbt/blob/v1.2.1/main/src/main/scala/sbt/Resolvers.scala#L145-L155
val git: Resolver = (info: ResolveInfo) => {
val uri = info.uri.withoutMarkerScheme
val localCopy = uniqueSubdirectoryFor(uri.copy(scheme = "git"), in = info.staging)
val from = uri.withoutFragment.toASCIIString
if (uri.hasFragment) {
val branch = uri.getFragment
Some { () =>
creates(localCopy) {
run("git", "clone", from, localCopy.getAbsolutePath)
run(Some(localCopy), "git", "checkout", "-q", branch)
}
}
} else
Some { () =>
creates(localCopy) {
run("git", "clone", "--depth", "1", from, localCopy.getAbsolutePath)
}
}
}
....
def creates(file: File)(f: => Unit) = {
if (!file.exists)
try {
f
} catch {
case NonFatal(e) =>
IO.delete(file)
throw e
}
file
}
How can I build and use my own version of SBT?
https://github.com/sbt/sbt/blob/1.x/CONTRIBUTING.md#build-from-source
For this, you just need sbt/sbt, and publishLocal.
I've been struggling in building automated build using Jenkins with symfony 3.4.
How to properly set environment variables in Jenkins that symfony can find it.
here's my pipeline.
node {
def app
stage('composer install') {
sh 'export $(cat env/env_vars | xargs)'
sh 'composer install --optimize-autoloader'
}
stage('yarn install') {
sh 'yarn install'
}
stage ('build assets') {
sh 'yarn encore production'
}
stage('Clone repository') {
// clone
}
stage('Build image') {
// build here
}
stage('Push image') {
// push here
}
}
then after I run my build.
I always got this message
....
Creating the "app/config/parameters.yml" file
Some parameters are missing. Please provide them.
database_host ('%env(DATABASE_HOST)%'): Script Incenteev\ParameterHandler
\ScriptHandler::buildParameters handling the symfony-scripts event terminated with an exception
[Symfony\Component\Console\Exception\RuntimeException]
Aborted
....
I already used some jenkins plugin like EnvInjector and something similar. But still symfony can't find my environment variables.
You can probably solve this like this:
stage('composer install') {
sh 'export $(cat env/env_vars | xargs) && composer install --optimize-autoloader'
}
This will make the environment variables available in the same shell session.
I know this question has been asked before but I tried the solutions given in other Threads with no success.
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/i2c
/I2CFactory at com.jksoft.rpi.dashpi.pishock.Sensor.setup(Sensor.java:32)
on my windows machine i used maven to get the pi4j dependency and for the I ran the curl statemet shown here (curl -s get.pi4j.com | sudo bash) an then tried to add the classes to the classpath with the command shown on that site: (sudo java -classpath .:classes:/opt/pi4j/lib/'*' ...)
In my case:
sudo java -classpath .:classes:/opt/pi4j/lib/'*':. -jar DashPi-1.0-SNAPSHOT.jar
but it still gives me that error and I dont know whats wrong.
Maybe this happens because pi4j has been installed unter
/opt/pi4j
and my jar is at
/home/pi
Any help would be appreciated!
the code looks as follows:
public Sensor(){
this.setup();
}
private void setup(){
try {
this.bus = I2CFactory.getInstance(I2CBus.BUS_1);
this.device = this.bus.getDevice(0x53);
} catch (IOException ex) {
Logger.getLogger(Sensor.class.getName()).log(Level.SEVERE, null, ex);
}
}
Why are you using the wildcard on that call? It seems that the classpath is wrong and should be something like:
sudo java -classpath .:classes:/opt/pi4j/lib/:. -jar DashPi-1.0-SNAPSHOT.jar
a program created folders recursively. it is too deep, the full path string length is longer than the MAX (getconf ARG_MAX), for example:
/A/B/C/A/B/C/A/B/C//A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C/A/B/C
……
so "sudo rm -fr /A" says "Bad address".
How to create a script to deal with it?
Thanks,
Interesting problem.
I guess you could create a command line tool with Xcode (file -> new project -> command line tool, insert code, then click the "run" toolbar button).
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSURL *url = [NSURL fileURLWithPath:#"/a/b/c/d/..."];
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtURL:url error:&error];
if (error) {
NSLog(#"%#", error);
}
}
return 0;
}
If it's a separate disk with its own filesystem mounted at /A, unmount it and reformat it.
If not, run something like this (very untested):
cd /A
then
cd A || cd B || cd C && rm -rf A* B* C*
and keep executing it, hitting up arrow to repeat and executing again till it works...
Good luck!