Skip to content

Commit 8681281

Browse files
Fixing deletion bug
1 parent f6e9a7d commit 8681281

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/checkRemoteBranchExistence.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616

1717
global gitConf
1818

19+
% remove .git from the remoteRepoURL
20+
if strcmpi(gitConf.remoteRepoURL(end-3:end), '.git')
21+
tmpRepoName = gitConf.remoteRepoURL(1:end-4);
22+
else
23+
tmpRepoName = gitConf.remoteRepoURL;
24+
end
25+
1926
% retrieve a list of all the branches
20-
[status_curl, result_curl] = system(['curl -s -k --head ' gitConf.remoteRepoURL '/tree/' branchName]);
27+
[status_curl, result_curl] = system(['curl -s -k --head ' tmpRepoName '/tree/' branchName]);
2128

2229
if status_curl == 0 && ~isempty(strfind(result_curl, '200 OK'))
2330
printMsg(mfilename, ['The branch <' branchName '> exists remotely.']);

src/deleteContribution.m

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ function deleteContribution(branchName)
3131
reply = input([gitCmd.lead, originCall, 'Are you sure that you want to delete the feature (branch) <', branchName, '>? YES/NO [NO]: '], 's');
3232

3333
if strcmpi(reply, 'yes') % users MUST enter 'yes', not only 'y'
34-
% checkout the develop branch
35-
checkoutBranch('develop');
34+
35+
% check if the develop branch exists remotely
36+
if checkRemoteBranchExistence('develop')
37+
mainBranch = 'develop';
38+
else
39+
mainBranch = 'master'; % fall back to master, which always exists
40+
end
41+
42+
% checkout the develop branch
43+
checkoutBranch(mainBranch);
3644

3745
% retrieve a list of all the branches
3846
if ispc
@@ -65,11 +73,8 @@ function deleteContribution(branchName)
6573
error([gitCmd.lead, ' [', mfilename,'] The list of features (branches) could not be retrieved.', gitCmd.fail]);
6674
end
6775

68-
% check if branch exists remotely
69-
[status_curl, result_curl] = system(['curl -s -k --head ', gitConf.remoteServerName, gitConf.userName, '/', gitConf.remoteRepoName, '/tree/', branchName]);
70-
7176
% delete the remote branch
72-
if status_curl == 0 && ~isempty(strfind(result_curl, '200 OK'))
77+
if checkRemoteBranchExistence(branchName)
7378

7479
[status_gitPush, result_gitPush] = system(['git push origin --delete ', branchName]);
7580

0 commit comments

Comments
 (0)