13 #include <StorageKit.h> 32 if (msg->FindRef(
"dir_ref", &dirRef) != B_OK) {
33 printf(
"No dir_ref found!\n");
40 return BString(path.Path());
57 msg->FindRef(
"refs", refs, &fileRef) == B_NO_ERROR;
60 entry.SetTo(&fileRef);
63 BString relativePath(path.Path());
65 relativePath.ReplaceFirst(dir,
"");
66 relativePath.ReplaceFirst(
"/",
"");
68 char* p = (
char*) malloc(relativePath.Length());
69 strcpy(p, relativePath.String());
70 selected.push_back(p);
84 git_buf buf = GIT_BUF_INIT_CONST(NULL, 0);
87 int ret = git_repository_discover(&buf, dirPath.String(), 0, NULL);
88 git_libgit2_shutdown();
92 return (ret == 0) ? BString(buf.ptr) : dirPath;
106 git_checkout_options ff_checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
107 git_reference *target_ref;
108 git_reference *new_target_ref;
109 git_object *target = NULL;
113 const char *symbolic_ref;
114 git_reference *head_ref;
119 err = git_reference_lookup(&head_ref, repo,
"HEAD");
121 fprintf(stderr,
"failed to lookup HEAD ref\n");
126 symbolic_ref = git_reference_symbolic_target(head_ref);
129 err = git_reference_create(&target_ref, repo, symbolic_ref,
130 target_oid, 0, NULL);
132 fprintf(stderr,
"failed to create master reference\n");
136 git_reference_free(head_ref);
139 err = git_repository_head(&target_ref, repo);
141 fprintf(stderr,
"failed to get HEAD reference\n");
147 err = git_object_lookup(&target, repo, target_oid, GIT_OBJ_COMMIT);
149 fprintf(stderr,
"failed to lookup OID %s\n",
150 git_oid_tostr_s(target_oid));
155 ff_checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
156 err = git_checkout_tree(repo, target, &ff_checkout_options);
158 fprintf(stderr,
"failed to checkout HEAD reference\n");
163 err = git_reference_set_target(&new_target_ref, target_ref, target_oid,
166 fprintf(stderr,
"failed to move HEAD reference\n");
170 git_reference_free(target_ref);
171 git_reference_free(new_target_ref);
172 git_object_free(target);
190 git_oid tree_id, commit_id, parent_id;
193 git_config* cfg_snapshot;
196 git_config_open_ondisk(&cfg,
"/boot/home/config/settings/git/config");
197 git_config_snapshot(&cfg_snapshot, cfg);
199 const char *user_name, *user_email;
200 ret = git_config_get_string(&user_name, cfg_snapshot,
"user.name");
204 ret = git_config_get_string(&user_email, cfg_snapshot,
"user.email");
209 ret = git_signature_now(&sign, user_name, user_email);
214 ret = git_index_write_tree(&tree_id, index);
218 git_index_free(index);
221 ret = git_tree_lookup(&tree, repo, &tree_id);
225 ret = git_reference_name_to_id(&parent_id, repo,
"HEAD");
228 ret = git_commit_create_v(&commit_id, repo,
"HEAD", sign, sign, NULL,
233 ret = git_commit_lookup(&parent, repo, &parent_id);
238 ret = git_commit_create_v(&commit_id, repo,
"HEAD", sign, sign, NULL,
239 message, tree, 1, parent);
251 git_index_conflict_iterator *conflicts;
252 const git_index_entry *ancestor;
253 const git_index_entry *our;
254 const git_index_entry *their;
256 BString conflictsString;
258 err = git_index_conflict_iterator_new(&conflicts, index);
260 conflictsString <<
"Failed to create conflict iterator!\n";
264 while ((err = git_index_conflict_next(&ancestor, &our, &their, conflicts))
266 conflictsString <<
"Conflict in file: " 267 <<
" a: " << (ancestor ? ancestor->path :
"NULL")
268 <<
" o: " << (our->path ? our->path :
"NULL")
269 <<
" t: " << (their->path ? their->path :
"NULL")
273 if (err != GIT_ITEROVER)
274 conflictsString <<
"Error iterating conflicts\n";
276 git_index_conflict_iterator_free(conflicts);
278 conflictsString <<
"\n" 279 <<
" a : Ancestor path\n" 281 <<
" t : Their path\n";
282 conflictsString <<
"Resolve the conflicts and add files to mark them as " 283 <<
"resolved.\nCommit changes after resolving all files.\n";
285 printf(
"%s\n", conflictsString.String());
286 conflictsWindow->
SetText(conflictsString);
288 thread_id thread = conflictsWindow->Thread();
290 status_t win_status = B_OK;
291 wait_for_thread(thread, &win_status);
300 const char* username_from_url,
unsigned int allowed_types,
303 char username[100] =
"",
307 thread_id thread = window->Thread();
309 status_t win_status = B_OK;
310 wait_for_thread(thread, &win_status);
312 return git_cred_userpass_plaintext_new(out, username, password);
void output_conflicts(git_index *index)
Shows conflicts in current repo index in a window.
int create_commit(git_repository *repo, git_index *index, const char *message)
Creates a commit on given repo, index and message.
void extract_selected_paths(const BMessage *msg, vector< char *> &selected)
Get selected files.
BString extract_current_directory(const BMessage *msg)
Get current directory.
int cred_acquire_cb(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload)
This functions gets username and password from the user in case credentials are required.
The Conflicts Window class.
BString get_root_of_repo(BString dirPath)
Get the root of repo of current directory.
void SetText(BString)
Sets Text of the View in Window.
int perform_fastforward(git_repository *repo, const git_oid *target_oid, int is_unborn)
This performs fastforward on given repo, branch id.
The Credentials Window class.
Header file of Conflicts window.