TrackGit
CreateBranch.cpp
Go to the documentation of this file.
1 
8 #include "CreateBranch.h"
9 #include "../UI/CreateBranchWindow.h"
10 
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <git2.h>
14 
15 
21 {
22  fRepo = repo;
23  fCreateBranchWindow = NULL;
24 }
25 
26 
30 void
32 {
33 }
34 
35 
42 {
43  if (fCreateBranchWindow == NULL)
45  return fCreateBranchWindow;
46 }
47 
48 
55 int
56 CreateBranch::DoCreateBranch(BString repoPath, BString branchName)
57 {
58  git_repository* repo;
59  git_reference *head, *branch;
60  git_commit* commit;
61  git_oid commit_oid;
62  const char *currentBranch = NULL;
63  int ret = 0;
64 
65  git_libgit2_init();
66 
67  ret = git_repository_open_ext(&repo, repoPath.String(), 0, NULL);
68  if (ret < 0)
69  return ret;
70 
71  ret = git_repository_head(&head, repo);
72  if (ret < 0)
73  return ret;
74 
75  currentBranch = git_reference_shorthand(head);
76 
77  ret = git_reference_name_to_id(&commit_oid, repo, "HEAD");
78  if (ret < 0)
79  return ret;
80 
81  ret = git_commit_lookup(&commit, repo, &commit_oid);
82  if (ret < 0)
83  return ret;
84 
85  ret = git_branch_create(&branch, repo, branchName.String(), commit, 0);
86 ret:
87  git_repository_free(repo);
88 
89  git_libgit2_shutdown();
90 
91  return ret;
92 }
The Create Branch Window class.
TrackGitWindow * fCreateBranchWindow
The Create Branch Window.
Definition: CreateBranch.h:26
static int DoCreateBranch(BString, BString)
This function creates a new branch in repo with given name.
virtual void Execute()
CreateBranch command execution.
Header file of Create Branch command.
CreateBranch(BString)
CreateBranch class constructor.
BString fRepo
The repo/directory where command is called.
Definition: CreateBranch.h:22
The TrackGit Window class.
virtual TrackGitWindow * GetWindow()
This returns pointer to the Create Branch window.