Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » stash in conflict doesn't return untracked file (issue with get status after stash conflict )
stash in conflict doesn't return untracked file [message #1747149] Thu, 10 November 2016 08:44 Go to next message
Yossi Balan is currently offline Yossi BalanFriend
Messages: 10
Registered: May 2013
Junior Member
This is my scenario

1. I did change on file a.

2. I created new file b

3. do stash

4. do change in file a.

5. do commit

6. do use stash

7. call to get status -> get only one file in conflit ( it is ok ) but I didn't get the file untracked b.



It is occurred only in this scenario without the conflict it is working ok

I am using jgit
code for stash

@Override
protected boolean handlePost(RequestInfo requestInfo) throws ServletException {

JSONObject requestPayload = requestInfo.getJSONRequest();
HttpServletRequest request = requestInfo.request;
HttpServletResponse response = requestInfo.response;
Repository db = requestInfo.db;

String indexMessage = requestPayload.optString(GitConstants.KEY_STASH_INDEX_MESSAGE);
String workingDirectoryMessage = requestPayload.optString(GitConstants.KEY_STASH_WORKING_DIRECTORY_MESSAGE);
boolean includeUntracked = requestPayload.optBoolean(GitConstants.KEY_STASH_INCLUDE_UNTRACKED, false);

try {

Git git = new Git(db);
StashCreateCommand stashCreate = git.stashCreate();
stashCreate.setPerson(new PersonIdent(db));
stashCreate.setIncludeUntracked(includeUntracked);

if (!indexMessage.isEmpty())
stashCreate.setIndexMessage(indexMessage);

if (!workingDirectoryMessage.isEmpty())
stashCreate.setWorkingDirectoryMessage(workingDirectoryMessage);

stashCreate.call();
return true;

} catch (Exception ex) {
String msg = "An error occured for stash command.";
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, ex));
}
}

code for use stash

@Override
protected boolean handlePut(RequestInfo requestInfo) throws ServletException {

JSONObject requestPayload = requestInfo.getJSONRequest();
HttpServletRequest request = requestInfo.request;
HttpServletResponse response = requestInfo.response;
Repository db = requestInfo.db;

/* gitapi/stash/<stashRev>/file/(...) */
String stashRev = requestInfo.gitSegment;

boolean applyIndex = requestPayload.optBoolean(GitConstants.KEY_STASH_APPLY_INDEX, true);
boolean applyUntracked = requestPayload.optBoolean(GitConstants.KEY_STASH_APPLY_UNTRACKED, true);

try {

Git git = new Git(db);

/* check for empty stash */
if (isStashEmpty(git)) {
String msg = "Failed to apply stashed changes due to an empty stash.";
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.WARNING, HttpServletResponse.SC_BAD_REQUEST, msg, null));
}

StashApplyCommand applyCommand = new StashApplyCommand(db);

if (stashRev != null) {

StashRef stashRef = getStashRef(git, stashRev);
if (stashRef == null) {
String msg = NLS.bind("Invalid stash reference {0}.", stashRev);
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
}

applyCommand.setStashRef(stashRef.getStringRef());
applyCommand.setApplyUntracked(applyUntracked);
applyCommand.setApplyIndex(applyIndex);
applyCommand.call();

} else {

/* git stash pop */
applyCommand.setApplyUntracked(applyUntracked);
applyCommand.setApplyIndex(applyIndex);
applyCommand.call();
StashDropCommand dropCommand = git.stashDrop();
dropCommand.setAll(false);
dropCommand.call();

}

return true;

} catch (GitAPIException gitEx) {
String msg = "An error occured for stash command issue with conflict.";
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.WARNING, HttpServletResponse.SC_CONFLICT, msg, gitEx));
} catch (Exception ex) {
String msg = "An error occured for stash command.";
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, ex));
}
}

code for commit

@Override
protected boolean handlePost(RequestInfo requestInfo) throws ServletException {
String gitSegment = requestInfo.gitSegment;
HttpServletRequest request = requestInfo.request;
HttpServletResponse response = requestInfo.response;
Repository db = requestInfo.db;
String pattern = requestInfo.relativePath;
JSONObject requestObject = requestInfo.getJSONRequest();
try {
String commitToMerge = requestObject.optString(GitConstants.KEY_MERGE, null);
if (commitToMerge != null) {
boolean squash = requestObject.optBoolean(GitConstants.KEY_SQUASH, false);
return merge(request, response, db, commitToMerge, squash);
}

String commitToRebase = requestObject.optString(GitConstants.KEY_REBASE, null);
String rebaseOperation = requestObject.optString(GitConstants.KEY_OPERATION, null);
if (commitToRebase != null) {
return rebase(request, response, db, commitToRebase, rebaseOperation);
}

String commitToCherryPick = requestObject.optString(GitConstants.KEY_CHERRY_PICK, null);
if (commitToCherryPick != null) {
return cherryPick(request, response, db, commitToCherryPick);
}

String commitToRevert = requestObject.optString(GitConstants.KEY_REVERT, null);
if (commitToRevert != null) {
return revert(request, response, db, commitToRevert);
}

String newCommit = requestObject.optString(GitConstants.KEY_COMMIT_NEW, null);
if (newCommit != null)
return identifyNewCommitResource(request, response, db, newCommit);

String reviewReqLogin = requestObject.optString(GitConstants.KEY_REVIEW_REQ_NOTIFY_LOGIN);
if (reviewReqLogin != null && reviewReqLogin.length() != 0) {
String reviewReqUrl = requestObject.optString(GitConstants.KEY_REVIEW_REQ_URL);
String ReviewReqCommit = requestObject.optString(GitConstants.KEY_REVIEW_REQ_COMMIT);
String ReviewReqAuthorName = requestObject.optString(GitConstants.KEY_REVIEW_REQ_AUTHOR_NAME);
String ReviewMessage = requestObject.optString(GitConstants.KEY_REVIEW_REQ_MESSAGE);
return sendNotification(request, response, db, reviewReqLogin, ReviewReqCommit, reviewReqUrl, ReviewReqAuthorName, ReviewMessage);
}

ObjectId refId = db.resolve(gitSegment);
if (refId == null || !Constants.HEAD.equals(gitSegment)) {
String msg = NLS.bind("Commit failed. Ref must be HEAD and is {0}", gitSegment);
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
}

String message = requestObject.optString(GitConstants.KEY_COMMIT_MESSAGE, null);
if (message == null || message.isEmpty()) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
"Missing commit message.", null));
}

Git git = new Git(db);
CommitCommand cc = git.commit();
Config config = git.getRepository().getConfig();

boolean amend = Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_COMMIT_AMEND, null));
boolean insertChangeId = config.getBoolean(ConfigConstants.CONFIG_GERRIT_SECTION, ConfigConstants.CONFIG_KEY_CREATECHANGEID, false)
|| Boolean.parseBoolean(requestObject.optString(GitConstants.KEY_CHANGE_ID, null));

String committerName = requestObject.optString(GitConstants.KEY_COMMITTER_NAME, null);
String committerEmail = requestObject.optString(GitConstants.KEY_COMMITTER_EMAIL, null);
String authorName = requestObject.optString(GitConstants.KEY_AUTHOR_NAME, null);
String authorEmail = requestObject.optString(GitConstants.KEY_AUTHOR_EMAIL, null);

// workaround of a bug in JGit which causes invalid
// support of null values of author/committer name/email, see bug
// 352984
PersonIdent defPersonIdent = new PersonIdent(db);
if (committerName == null)
committerName = defPersonIdent.getName();
if (committerEmail == null)
committerEmail = defPersonIdent.getEmailAddress();
if (authorName == null)
authorName = committerName;
if (authorEmail == null)
authorEmail = committerEmail;
cc.setCommitter(committerName, committerEmail);
cc.setAuthor(authorName, authorEmail);
if (insertChangeId)
cc.setInsertChangeId(true);

// support for committing by path: "git commit -o path"
if (!pattern.isEmpty()) {
cc.setOnly(pattern);
}

try {
// "git commit [--amend] -m '{message}' [-a|{path}]"
RevCommit lastCommit = cc.setAmend(amend).setMessage(message).call();

URI cloneLocation = BaseToCloneConverter.getCloneLocation(getURI(request), BaseToCloneConverter.COMMIT_REFRANGE);
Commit commit = new Commit(cloneLocation, db, lastCommit, pattern);
JSONObject result = commit.toJSON();
OrionServlet.writeJSONResponse(request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
return true;
} catch (GitAPIException e) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST,
"An error occurred when committing.", e));
} catch (UnmergedPathException e) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"An internal error occurred when committing.", e));
}
} catch (Exception e) {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"An error occurred when requesting commit information.", e));
}
}

code for get status
@Override
protected boolean handleGet(RequestInfo requestInfo) throws ServletException {

HttpServletRequest request = requestInfo.request;
HttpServletResponse response = requestInfo.response;
Repository db = requestInfo.db;

int page = request.getParameter("page") != null ? new Integer(request.getParameter("page")).intValue() : 1; //$NON-NLS-1$ //$NON-NLS-2$
int pageSize = request.getParameter("pageSize") != null ? new Integer(request.getParameter("pageSize")).intValue() : PAGE_SIZE; //$NON-NLS-1$ //$NON-NLS-2$
String messageFilter = request.getParameter("filter"); //$NON-NLS-1$
try {

URI baseLocation = getURI(request);
URI cloneLocation = BaseToCloneConverter.getCloneLocation(baseLocation, BaseToCloneConverter.COMMIT);

Git git = new Git(db);
StashListCommand stashList = git.stashList();
Collection<RevCommit> stashedRefsCollection = stashList.call();

StashPage stashPage = new StashPage(cloneLocation, db, stashedRefsCollection, page, pageSize, messageFilter);
OrionServlet.writeJSONResponse(request, response, stashPage.toJSON());
return true;

} catch (Exception ex) {
String msg = "An error occured for stash command.";
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, ex));
}
}
Re: stash in conflict doesn't return untracked file [message #1747150 is a reply to message #1747149] Thu, 10 November 2016 08:53 Go to previous messageGo to next message
Yossi Balan is currently offline Yossi BalanFriend
Messages: 10
Registered: May 2013
Junior Member
The jgit version is org.eclipse.jgit,3.4.2.201412180340-r
Re: stash in conflict doesn't return untracked file [message #1749109 is a reply to message #1747150] Thu, 01 December 2016 22:09 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Why are you using such an outdated version of jgit ? The latest release is 4.5.0.201609210915-r.

Do you have a repository containing this code which I can clone to try it ?
Previous Topic:EGit modifies index for certain files when project is refreshed
Next Topic:jgit console
Goto Forum:
  


Current Time: Fri Mar 29 08:46:49 GMT 2024

Powered by FUDForum. Page generated in 0.03219 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top