rdavila-rugged 0.24.0b13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +619 -0
- data/ext/rugged/extconf.rb +105 -0
- data/ext/rugged/rugged.c +527 -0
- data/ext/rugged/rugged.h +185 -0
- data/ext/rugged/rugged_backend.c +34 -0
- data/ext/rugged/rugged_blame.c +292 -0
- data/ext/rugged/rugged_blob.c +638 -0
- data/ext/rugged/rugged_branch.c +195 -0
- data/ext/rugged/rugged_branch_collection.c +408 -0
- data/ext/rugged/rugged_commit.c +691 -0
- data/ext/rugged/rugged_config.c +404 -0
- data/ext/rugged/rugged_cred.c +148 -0
- data/ext/rugged/rugged_diff.c +686 -0
- data/ext/rugged/rugged_diff_delta.c +105 -0
- data/ext/rugged/rugged_diff_hunk.c +103 -0
- data/ext/rugged/rugged_diff_line.c +83 -0
- data/ext/rugged/rugged_index.c +1255 -0
- data/ext/rugged/rugged_note.c +376 -0
- data/ext/rugged/rugged_object.c +383 -0
- data/ext/rugged/rugged_patch.c +245 -0
- data/ext/rugged/rugged_reference.c +396 -0
- data/ext/rugged/rugged_reference_collection.c +446 -0
- data/ext/rugged/rugged_remote.c +691 -0
- data/ext/rugged/rugged_remote_collection.c +457 -0
- data/ext/rugged/rugged_repo.c +2669 -0
- data/ext/rugged/rugged_revwalk.c +495 -0
- data/ext/rugged/rugged_settings.c +155 -0
- data/ext/rugged/rugged_signature.c +106 -0
- data/ext/rugged/rugged_submodule.c +852 -0
- data/ext/rugged/rugged_submodule_collection.c +384 -0
- data/ext/rugged/rugged_tag.c +251 -0
- data/ext/rugged/rugged_tag_collection.c +347 -0
- data/ext/rugged/rugged_tree.c +919 -0
- data/lib/rugged.rb +23 -0
- data/lib/rugged/attributes.rb +41 -0
- data/lib/rugged/blob.rb +28 -0
- data/lib/rugged/branch.rb +19 -0
- data/lib/rugged/commit.rb +54 -0
- data/lib/rugged/console.rb +9 -0
- data/lib/rugged/credentials.rb +43 -0
- data/lib/rugged/diff.rb +20 -0
- data/lib/rugged/diff/delta.rb +53 -0
- data/lib/rugged/diff/hunk.rb +18 -0
- data/lib/rugged/diff/line.rb +47 -0
- data/lib/rugged/index.rb +13 -0
- data/lib/rugged/object.rb +7 -0
- data/lib/rugged/patch.rb +36 -0
- data/lib/rugged/reference.rb +7 -0
- data/lib/rugged/remote.rb +4 -0
- data/lib/rugged/repository.rb +227 -0
- data/lib/rugged/submodule_collection.rb +48 -0
- data/lib/rugged/tag.rb +50 -0
- data/lib/rugged/tree.rb +38 -0
- data/lib/rugged/version.rb +3 -0
- data/lib/rugged/walker.rb +5 -0
- metadata +146 -0
@@ -0,0 +1,155 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright (c) 2014 GitHub, Inc
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
* THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include "rugged.h"
|
26
|
+
|
27
|
+
#if !defined(NUM2SIZET)
|
28
|
+
# if SIZEOF_SIZE_T == SIZEOF_LONG
|
29
|
+
# define NUM2SIZET(n) ((size_t)NUM2ULONG(n))
|
30
|
+
# define SIZET2NUM(n) ((size_t)ULONG2NUM(n))
|
31
|
+
# else
|
32
|
+
# define NUM2SIZET(n) ((size_t)NUM2ULL(n))
|
33
|
+
# define SIZET2NUM(n) ((size_t)ULL2NUM(n))
|
34
|
+
# endif
|
35
|
+
#endif /* ! defined(NUM2SIZET) */
|
36
|
+
|
37
|
+
extern VALUE rb_mRugged;
|
38
|
+
|
39
|
+
static void set_search_path(int level, VALUE value)
|
40
|
+
{
|
41
|
+
const char *path;
|
42
|
+
|
43
|
+
Check_Type(value, T_STRING);
|
44
|
+
path = StringValueCStr(value);
|
45
|
+
|
46
|
+
rugged_exception_check(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, level, path));
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE get_search_path(int level)
|
50
|
+
{
|
51
|
+
git_buf buf = {NULL};
|
52
|
+
VALUE ret;
|
53
|
+
|
54
|
+
rugged_exception_check(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, level, &buf));
|
55
|
+
|
56
|
+
ret = rb_str_new_utf8(buf.ptr);
|
57
|
+
git_buf_free(&buf);
|
58
|
+
|
59
|
+
return ret;
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
* call-seq:
|
64
|
+
* Settings[option] = value
|
65
|
+
*
|
66
|
+
* Sets a libgit2 library option.
|
67
|
+
*/
|
68
|
+
static VALUE rb_git_set_option(VALUE self, VALUE option, VALUE value)
|
69
|
+
{
|
70
|
+
const char *opt;
|
71
|
+
|
72
|
+
Check_Type(option, T_STRING);
|
73
|
+
opt = StringValueCStr(option);
|
74
|
+
|
75
|
+
if (strcmp(opt, "mwindow_size") == 0) {
|
76
|
+
size_t val;
|
77
|
+
Check_Type(value, T_FIXNUM);
|
78
|
+
val = NUM2SIZET(value);
|
79
|
+
git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, val);
|
80
|
+
}
|
81
|
+
|
82
|
+
else if (strcmp(opt, "mwindow_mapped_limit") == 0) {
|
83
|
+
size_t val;
|
84
|
+
Check_Type(value, T_FIXNUM);
|
85
|
+
val = NUM2SIZET(value);
|
86
|
+
git_libgit2_opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, val);
|
87
|
+
}
|
88
|
+
|
89
|
+
else if (strcmp(opt, "search_path_global") == 0) {
|
90
|
+
set_search_path(GIT_CONFIG_LEVEL_GLOBAL, value);
|
91
|
+
}
|
92
|
+
|
93
|
+
else if (strcmp(opt, "search_path_xdg") == 0) {
|
94
|
+
set_search_path(GIT_CONFIG_LEVEL_XDG, value);
|
95
|
+
}
|
96
|
+
|
97
|
+
else if (strcmp(opt, "search_path_system") == 0) {
|
98
|
+
set_search_path(GIT_CONFIG_LEVEL_SYSTEM, value);
|
99
|
+
}
|
100
|
+
|
101
|
+
else {
|
102
|
+
rb_raise(rb_eArgError, "Unknown option specified");
|
103
|
+
}
|
104
|
+
|
105
|
+
return Qnil;
|
106
|
+
}
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* Settings[option] -> value
|
111
|
+
*
|
112
|
+
* Gets the value of a libgit2 library option.
|
113
|
+
*/
|
114
|
+
static VALUE rb_git_get_option(VALUE self, VALUE option)
|
115
|
+
{
|
116
|
+
const char *opt;
|
117
|
+
|
118
|
+
Check_Type(option, T_STRING);
|
119
|
+
opt = StringValueCStr(option);
|
120
|
+
|
121
|
+
if (strcmp(opt, "mwindow_size") == 0) {
|
122
|
+
size_t val;
|
123
|
+
git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &val);
|
124
|
+
return SIZET2NUM(val);
|
125
|
+
}
|
126
|
+
|
127
|
+
else if (strcmp(opt, "mwindow_mapped_limit") == 0) {
|
128
|
+
size_t val;
|
129
|
+
git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &val);
|
130
|
+
return SIZET2NUM(val);
|
131
|
+
}
|
132
|
+
|
133
|
+
else if (strcmp(opt, "search_path_global") == 0) {
|
134
|
+
return get_search_path(GIT_CONFIG_LEVEL_GLOBAL);
|
135
|
+
}
|
136
|
+
|
137
|
+
else if (strcmp(opt, "search_path_xdg") == 0) {
|
138
|
+
return get_search_path(GIT_CONFIG_LEVEL_XDG);
|
139
|
+
}
|
140
|
+
|
141
|
+
else if (strcmp(opt, "search_path_system") == 0) {
|
142
|
+
return get_search_path(GIT_CONFIG_LEVEL_SYSTEM);
|
143
|
+
}
|
144
|
+
|
145
|
+
else {
|
146
|
+
rb_raise(rb_eArgError, "Unknown option specified");
|
147
|
+
}
|
148
|
+
}
|
149
|
+
|
150
|
+
void Init_rugged_settings(void)
|
151
|
+
{
|
152
|
+
VALUE rb_cRuggedSettings = rb_define_class_under(rb_mRugged, "Settings", rb_cObject);
|
153
|
+
rb_define_module_function(rb_cRuggedSettings, "[]=", rb_git_set_option, 2);
|
154
|
+
rb_define_module_function(rb_cRuggedSettings, "[]", rb_git_get_option, 1);
|
155
|
+
}
|
@@ -0,0 +1,106 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright (c) 2014 GitHub, Inc
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
* THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include "rugged.h"
|
26
|
+
|
27
|
+
VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name)
|
28
|
+
{
|
29
|
+
VALUE rb_sig, rb_time;
|
30
|
+
rb_encoding *encoding = rb_utf8_encoding();
|
31
|
+
|
32
|
+
if (encoding_name != NULL)
|
33
|
+
encoding = rb_enc_find(encoding_name);
|
34
|
+
|
35
|
+
rb_sig = rb_hash_new();
|
36
|
+
|
37
|
+
/* Allocate the time with a the given timezone */
|
38
|
+
rb_time = rb_funcall(
|
39
|
+
rb_time_new(sig->when.time, 0),
|
40
|
+
rb_intern("getlocal"), 1,
|
41
|
+
INT2FIX(sig->when.offset * 60)
|
42
|
+
);
|
43
|
+
|
44
|
+
rb_hash_aset(rb_sig, CSTR2SYM("name"),
|
45
|
+
rb_enc_str_new(sig->name, strlen(sig->name), encoding));
|
46
|
+
|
47
|
+
rb_hash_aset(rb_sig, CSTR2SYM("email"),
|
48
|
+
rb_enc_str_new(sig->email, strlen(sig->email), encoding));
|
49
|
+
|
50
|
+
rb_hash_aset(rb_sig, CSTR2SYM("time"), rb_time);
|
51
|
+
|
52
|
+
return rb_sig;
|
53
|
+
}
|
54
|
+
|
55
|
+
git_signature *rugged_signature_get(VALUE rb_sig, git_repository *repo)
|
56
|
+
{
|
57
|
+
int error;
|
58
|
+
VALUE rb_time, rb_unix_t, rb_offset, rb_name, rb_email, rb_time_offset;
|
59
|
+
git_signature *sig;
|
60
|
+
|
61
|
+
if (NIL_P(rb_sig)) {
|
62
|
+
rugged_exception_check(
|
63
|
+
git_signature_default(&sig, repo)
|
64
|
+
);
|
65
|
+
return sig;
|
66
|
+
}
|
67
|
+
|
68
|
+
Check_Type(rb_sig, T_HASH);
|
69
|
+
|
70
|
+
rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name"));
|
71
|
+
rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email"));
|
72
|
+
rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time"));
|
73
|
+
rb_time_offset = rb_hash_aref(rb_sig, CSTR2SYM("time_offset"));
|
74
|
+
|
75
|
+
Check_Type(rb_name, T_STRING);
|
76
|
+
Check_Type(rb_email, T_STRING);
|
77
|
+
|
78
|
+
|
79
|
+
if (NIL_P(rb_time)) {
|
80
|
+
error = git_signature_now(&sig,
|
81
|
+
StringValueCStr(rb_name),
|
82
|
+
StringValueCStr(rb_email));
|
83
|
+
} else {
|
84
|
+
if (!rb_obj_is_kind_of(rb_time, rb_cTime))
|
85
|
+
rb_raise(rb_eTypeError, "expected Time object");
|
86
|
+
|
87
|
+
rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0);
|
88
|
+
|
89
|
+
if (NIL_P(rb_time_offset)) {
|
90
|
+
rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0);
|
91
|
+
} else {
|
92
|
+
Check_Type(rb_time_offset, T_FIXNUM);
|
93
|
+
rb_offset = rb_time_offset;
|
94
|
+
}
|
95
|
+
|
96
|
+
error = git_signature_new(&sig,
|
97
|
+
StringValueCStr(rb_name),
|
98
|
+
StringValueCStr(rb_email),
|
99
|
+
NUM2LONG(rb_unix_t),
|
100
|
+
FIX2INT(rb_offset) / 60);
|
101
|
+
}
|
102
|
+
|
103
|
+
rugged_exception_check(error);
|
104
|
+
|
105
|
+
return sig;
|
106
|
+
}
|
@@ -0,0 +1,852 @@
|
|
1
|
+
/*
|
2
|
+
* The MIT License
|
3
|
+
*
|
4
|
+
* Copyright (c) 2014 GitHub, Inc
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
11
|
+
* furnished to do so, subject to the following conditions:
|
12
|
+
*
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
14
|
+
* all copies or substantial portions of the Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
* THE SOFTWARE.
|
23
|
+
*/
|
24
|
+
|
25
|
+
#include "rugged.h"
|
26
|
+
extern VALUE rb_mRugged;
|
27
|
+
VALUE rb_cRuggedSubmodule;
|
28
|
+
|
29
|
+
static VALUE id_in_head, id_in_index, id_in_config, id_in_workdir;
|
30
|
+
static VALUE id_index_added, id_index_deleted, id_index_modified;
|
31
|
+
static VALUE id_wd_uninitialized, id_wd_added, id_wd_deleted, id_wd_modified;
|
32
|
+
static VALUE id_wd_index_modified, id_wd_wd_modified, id_wd_untracked;
|
33
|
+
|
34
|
+
static ID id_ignore_none, id_ignore_untracked, id_ignore_dirty, id_ignore_all;
|
35
|
+
|
36
|
+
static ID id_update_checkout, id_update_rebase, id_update_merge, id_update_none;
|
37
|
+
|
38
|
+
void init_status_list(void)
|
39
|
+
{
|
40
|
+
id_in_head = CSTR2SYM("in_head");
|
41
|
+
id_in_index = CSTR2SYM("in_index");
|
42
|
+
id_in_config = CSTR2SYM("in_config");
|
43
|
+
id_in_workdir = CSTR2SYM("in_workdir");
|
44
|
+
id_index_added = CSTR2SYM("added_to_index");
|
45
|
+
id_index_deleted = CSTR2SYM("deleted_from_index");
|
46
|
+
id_index_modified = CSTR2SYM("modified_in_index");
|
47
|
+
id_wd_uninitialized = CSTR2SYM("uninitialized");
|
48
|
+
id_wd_added = CSTR2SYM("added_to_workdir");
|
49
|
+
id_wd_deleted = CSTR2SYM("deleted_from_workdir");
|
50
|
+
id_wd_modified = CSTR2SYM("modified_in_workdir");
|
51
|
+
id_wd_index_modified = CSTR2SYM("dirty_workdir_index");
|
52
|
+
id_wd_wd_modified = CSTR2SYM("modified_files_in_workdir");
|
53
|
+
id_wd_untracked = CSTR2SYM("untracked_files_in_workdir");
|
54
|
+
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
|
58
|
+
static VALUE submodule_status_flags_to_rb(unsigned int flags)
|
59
|
+
{
|
60
|
+
VALUE rb_flags = rb_ary_new();
|
61
|
+
|
62
|
+
if (flags & GIT_SUBMODULE_STATUS_IN_HEAD)
|
63
|
+
rb_ary_push(rb_flags, id_in_head);
|
64
|
+
|
65
|
+
if (flags & GIT_SUBMODULE_STATUS_IN_INDEX)
|
66
|
+
rb_ary_push(rb_flags, id_in_index);
|
67
|
+
|
68
|
+
if (flags & GIT_SUBMODULE_STATUS_IN_CONFIG)
|
69
|
+
rb_ary_push(rb_flags, id_in_config);
|
70
|
+
|
71
|
+
if (flags & GIT_SUBMODULE_STATUS_IN_WD)
|
72
|
+
rb_ary_push(rb_flags, id_in_workdir);
|
73
|
+
|
74
|
+
if (flags & GIT_SUBMODULE_STATUS_INDEX_ADDED)
|
75
|
+
rb_ary_push(rb_flags, id_index_added);
|
76
|
+
|
77
|
+
if (flags & GIT_SUBMODULE_STATUS_INDEX_DELETED)
|
78
|
+
rb_ary_push(rb_flags, id_index_deleted);
|
79
|
+
|
80
|
+
if (flags & GIT_SUBMODULE_STATUS_INDEX_MODIFIED)
|
81
|
+
rb_ary_push(rb_flags, id_index_modified);
|
82
|
+
|
83
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)
|
84
|
+
rb_ary_push(rb_flags, id_wd_uninitialized);
|
85
|
+
|
86
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_ADDED)
|
87
|
+
rb_ary_push(rb_flags, id_wd_added);
|
88
|
+
|
89
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_DELETED)
|
90
|
+
rb_ary_push(rb_flags, id_wd_deleted);
|
91
|
+
|
92
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_MODIFIED)
|
93
|
+
rb_ary_push(rb_flags, id_wd_modified);
|
94
|
+
|
95
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
|
96
|
+
rb_ary_push(rb_flags, id_wd_index_modified);
|
97
|
+
|
98
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
|
99
|
+
rb_ary_push(rb_flags, id_wd_wd_modified);
|
100
|
+
|
101
|
+
if (flags & GIT_SUBMODULE_STATUS_WD_UNTRACKED)
|
102
|
+
rb_ary_push(rb_flags, id_wd_untracked);
|
103
|
+
|
104
|
+
return rb_flags;
|
105
|
+
}
|
106
|
+
|
107
|
+
/*
|
108
|
+
* call-seq:
|
109
|
+
* submodule.status -> array
|
110
|
+
*
|
111
|
+
* Returns an +array+ with the status flags for a submodule.
|
112
|
+
*
|
113
|
+
* Depending on the #ignore_rule property of the submodule, some of
|
114
|
+
* the flags may never be returned because they indicate changes that are
|
115
|
+
* supposed to be ignored.
|
116
|
+
*
|
117
|
+
* Submodule info is contained in 4 places: the +HEAD+ tree, the index,
|
118
|
+
* config files (both +.git/config+ and +.gitmodules+), and the working
|
119
|
+
* directory. Any or all of those places might be missing information about
|
120
|
+
* the submodule depending on what state the repository is in. We consider
|
121
|
+
* all four places to build the combination of status flags.
|
122
|
+
*
|
123
|
+
* There are four values that are not really status, but give basic info
|
124
|
+
* about what sources of submodule data are available. These will be
|
125
|
+
* returned even if ignore is set to +:all+.
|
126
|
+
*
|
127
|
+
* :in_head ::
|
128
|
+
* superproject +HEAD+ contains submodule
|
129
|
+
* :in_index ::
|
130
|
+
* superproject index contains submodule
|
131
|
+
* :in_config ::
|
132
|
+
* superproject +.gitmodules+ has submodule
|
133
|
+
* :in_workdir ::
|
134
|
+
* superproject workdir has submodule
|
135
|
+
*
|
136
|
+
* The following values will be returned as long as ignore is not +:all+.
|
137
|
+
*
|
138
|
+
* :added_to_index ::
|
139
|
+
* submodule is in index, not in +HEAD+
|
140
|
+
* :deleted_from_index ::
|
141
|
+
* submodule is in +HEAD+, not in index
|
142
|
+
* :modified_in_index ::
|
143
|
+
* submodule in index and +HEAD+ don't match
|
144
|
+
* :uninitialized ::
|
145
|
+
* submodule in workdir is not initialized
|
146
|
+
* :added_to_workdir ::
|
147
|
+
* submodule is in workdir, not index
|
148
|
+
* :deleted_from_workdir ::
|
149
|
+
* submodule is in index, not workdir
|
150
|
+
* :modified_in_workdir ::
|
151
|
+
* submodule in index and workdir +HEAD+ don't match
|
152
|
+
*
|
153
|
+
* The following can only be returned if ignore is +:none+ or +:untracked+.
|
154
|
+
*
|
155
|
+
* :dirty_workdir_index ::
|
156
|
+
* submodule workdir index is dirty
|
157
|
+
* :modified_files_in_workdir ::
|
158
|
+
* submodule workdir has modified files
|
159
|
+
*
|
160
|
+
* Lastly, the following will only be returned for ignore +:none+.
|
161
|
+
*
|
162
|
+
* :untracked_files_in_workdir ::
|
163
|
+
* submodule workdir contains untracked files
|
164
|
+
*/
|
165
|
+
static VALUE rb_git_submodule_status(VALUE self)
|
166
|
+
{
|
167
|
+
VALUE rb_repo = rugged_owner(self);
|
168
|
+
git_submodule *submodule;
|
169
|
+
git_repository *repo;
|
170
|
+
unsigned int flags;
|
171
|
+
|
172
|
+
rugged_check_repo(rb_repo);
|
173
|
+
Data_Get_Struct(rb_repo, git_repository, repo);
|
174
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
175
|
+
|
176
|
+
rugged_exception_check(
|
177
|
+
git_submodule_status(&flags, repo, git_submodule_name(submodule),
|
178
|
+
GIT_SUBMODULE_IGNORE_UNSPECIFIED)
|
179
|
+
);
|
180
|
+
|
181
|
+
return submodule_status_flags_to_rb(flags);
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
#define RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(flag) \
|
186
|
+
git_submodule *submodule; \
|
187
|
+
unsigned int flags; \
|
188
|
+
Data_Get_Struct(self, git_submodule, submodule); \
|
189
|
+
rugged_exception_check( \
|
190
|
+
git_submodule_location(&flags, submodule) \
|
191
|
+
); \
|
192
|
+
return (flags & flag) ? Qtrue : Qfalse; \
|
193
|
+
|
194
|
+
/*
|
195
|
+
* call-seq:
|
196
|
+
* submodule.in_head? -> true or false
|
197
|
+
*
|
198
|
+
* Returns +true+ if superproject +HEAD+ contains submodule.
|
199
|
+
*/
|
200
|
+
static VALUE rb_git_submodule_status_in_head(VALUE self)
|
201
|
+
{
|
202
|
+
RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_HEAD)
|
203
|
+
}
|
204
|
+
|
205
|
+
/*
|
206
|
+
* call-seq:
|
207
|
+
* submodule.in_index? -> true or false
|
208
|
+
*
|
209
|
+
* Returns +true+ if superproject index contains submodule.
|
210
|
+
*/
|
211
|
+
static VALUE rb_git_submodule_status_in_index(VALUE self)
|
212
|
+
{
|
213
|
+
RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_INDEX)
|
214
|
+
}
|
215
|
+
|
216
|
+
/*
|
217
|
+
* call-seq:
|
218
|
+
* submodule.in_config? -> true or false
|
219
|
+
*
|
220
|
+
* Returns +true+ if superproject +.gitmodules+ has submodule.
|
221
|
+
*/
|
222
|
+
static VALUE rb_git_submodule_status_in_config(VALUE self)
|
223
|
+
{
|
224
|
+
RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_CONFIG)
|
225
|
+
}
|
226
|
+
|
227
|
+
/*
|
228
|
+
* call-seq:
|
229
|
+
* submodule.in_workdir? -> true or false
|
230
|
+
*
|
231
|
+
* Returns +true+ if superproject workdir has submodule.
|
232
|
+
*/
|
233
|
+
static VALUE rb_git_submodule_status_in_workdir(VALUE self)
|
234
|
+
{
|
235
|
+
RB_GIT_SUBMODULE_LOCATION_FLAG_CHECK(GIT_SUBMODULE_STATUS_IN_WD)
|
236
|
+
}
|
237
|
+
|
238
|
+
#define RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(flag) \
|
239
|
+
VALUE rb_repo = rugged_owner(self); \
|
240
|
+
git_repository *repo; \
|
241
|
+
git_submodule *submodule; \
|
242
|
+
unsigned int flags; \
|
243
|
+
rugged_check_repo(rb_repo); \
|
244
|
+
Data_Get_Struct(rb_repo, git_repository, repo); \
|
245
|
+
Data_Get_Struct(self, git_submodule, submodule); \
|
246
|
+
rugged_exception_check( \
|
247
|
+
git_submodule_status(&flags, repo, git_submodule_name(submodule), \
|
248
|
+
GIT_SUBMODULE_IGNORE_UNSPECIFIED) \
|
249
|
+
); \
|
250
|
+
return (flags & flag) ? Qtrue : Qfalse; \
|
251
|
+
|
252
|
+
/*
|
253
|
+
* call-seq:
|
254
|
+
* submodule.added_to_index? -> true or false
|
255
|
+
*
|
256
|
+
* Returns +true+ if submodule is in index, not in +HEAD+.
|
257
|
+
*/
|
258
|
+
static VALUE rb_git_submodule_status_added_to_index(VALUE self)
|
259
|
+
{
|
260
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_ADDED)
|
261
|
+
}
|
262
|
+
|
263
|
+
/*
|
264
|
+
* call-seq:
|
265
|
+
* submodule.deleted_from_index? -> true or false
|
266
|
+
*
|
267
|
+
* Returns +true+ if submodule is in +HEAD+, not in index
|
268
|
+
*/
|
269
|
+
static VALUE rb_git_submodule_status_deleted_from_index(VALUE self)
|
270
|
+
{
|
271
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_DELETED)
|
272
|
+
}
|
273
|
+
|
274
|
+
/*
|
275
|
+
* call-seq:
|
276
|
+
* submodule.modified_in_index? -> true or false
|
277
|
+
*
|
278
|
+
* Returns +true+ if submodule in index and +HEAD+ don't match.
|
279
|
+
*/
|
280
|
+
static VALUE rb_git_submodule_status_modified_in_index(VALUE self)
|
281
|
+
{
|
282
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_INDEX_MODIFIED)
|
283
|
+
}
|
284
|
+
|
285
|
+
/*
|
286
|
+
* call-seq:
|
287
|
+
* submodule.uninitialized? -> true or false
|
288
|
+
*
|
289
|
+
* Returns +true+ if submodule in workdir is not initialized.
|
290
|
+
*/
|
291
|
+
static VALUE rb_git_submodule_status_uninitialized(VALUE self)
|
292
|
+
{
|
293
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_UNINITIALIZED)
|
294
|
+
}
|
295
|
+
|
296
|
+
/*
|
297
|
+
* call-seq:
|
298
|
+
* submodule.added_to_workdir? -> true or false
|
299
|
+
*
|
300
|
+
* Returns +true+ if submodule is in workdir, not index.
|
301
|
+
*/
|
302
|
+
static VALUE rb_git_submodule_status_added_to_workdir(VALUE self)
|
303
|
+
{
|
304
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_ADDED)
|
305
|
+
}
|
306
|
+
|
307
|
+
/*
|
308
|
+
* call-seq:
|
309
|
+
* submodule.deleted_from_workdir? -> true or false
|
310
|
+
*
|
311
|
+
* Returns +true+ if submodule is in index, not workdir.
|
312
|
+
*/
|
313
|
+
static VALUE rb_git_submodule_status_deleted_from_workdir(VALUE self)
|
314
|
+
{
|
315
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_DELETED)
|
316
|
+
}
|
317
|
+
|
318
|
+
/*
|
319
|
+
* call-seq:
|
320
|
+
* submodule.modified_in_workdir? -> true or false
|
321
|
+
*
|
322
|
+
* Returns +true+ if submodule in index and workdir +HEAD+ don't match.
|
323
|
+
*/
|
324
|
+
static VALUE rb_git_submodule_status_modified_in_workdir(VALUE self)
|
325
|
+
{
|
326
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_MODIFIED)
|
327
|
+
}
|
328
|
+
|
329
|
+
/*
|
330
|
+
* call-seq:
|
331
|
+
* submodule.dirty_workdir_index? -> true or false
|
332
|
+
*
|
333
|
+
* Returns +true+ if submodule workdir index is dirty.
|
334
|
+
*/
|
335
|
+
static VALUE rb_git_submodule_status_dirty_workdir_index(VALUE self)
|
336
|
+
{
|
337
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED)
|
338
|
+
}
|
339
|
+
|
340
|
+
/*
|
341
|
+
* call-seq:
|
342
|
+
* submodule.modified_files_in_workdir? -> true or false
|
343
|
+
*
|
344
|
+
* Returns +true+ if submodule workdir has modified files.
|
345
|
+
*/
|
346
|
+
static VALUE rb_git_submodule_status_modified_files_in_workdir(VALUE self)
|
347
|
+
{
|
348
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_WD_MODIFIED)
|
349
|
+
}
|
350
|
+
|
351
|
+
/*
|
352
|
+
* call-seq:
|
353
|
+
* submodule.untracked_files_in_workdir? -> true or false
|
354
|
+
*
|
355
|
+
* Returns +true+ if submodule workdir contains untracked files.
|
356
|
+
*/
|
357
|
+
static VALUE rb_git_submodule_status_untracked_files_in_workdir(VALUE self)
|
358
|
+
{
|
359
|
+
RB_GIT_SUBMODULE_STATUS_FLAG_CHECK(GIT_SUBMODULE_STATUS_WD_UNTRACKED)
|
360
|
+
}
|
361
|
+
|
362
|
+
#define RB_GIT_SUBMODULE_STATUS_CHECK(check) \
|
363
|
+
VALUE rb_repo = rugged_owner(self); \
|
364
|
+
git_repository *repo; \
|
365
|
+
git_submodule *submodule; \
|
366
|
+
unsigned int flags; \
|
367
|
+
rugged_check_repo(rb_repo); \
|
368
|
+
Data_Get_Struct(rb_repo, git_repository, repo); \
|
369
|
+
Data_Get_Struct(self, git_submodule, submodule); \
|
370
|
+
rugged_exception_check( \
|
371
|
+
git_submodule_status(&flags, repo, git_submodule_name(submodule), \
|
372
|
+
GIT_SUBMODULE_IGNORE_UNSPECIFIED) \
|
373
|
+
); \
|
374
|
+
return check(flags) ? Qtrue : Qfalse; \
|
375
|
+
|
376
|
+
/*
|
377
|
+
* call-seq:
|
378
|
+
* submodule.unmodified? -> true or false
|
379
|
+
*
|
380
|
+
* Returns +true+ if the submodule is unmodified.
|
381
|
+
*/
|
382
|
+
static VALUE rb_git_submodule_status_unmodified(VALUE self)
|
383
|
+
{
|
384
|
+
RB_GIT_SUBMODULE_STATUS_CHECK(GIT_SUBMODULE_STATUS_IS_UNMODIFIED)
|
385
|
+
}
|
386
|
+
|
387
|
+
/*
|
388
|
+
* call-seq:
|
389
|
+
* submodule.dirty_workdir? -> true or false
|
390
|
+
*
|
391
|
+
* Returns +true+ if the submodule workdir is dirty.
|
392
|
+
*
|
393
|
+
* The workdir is considered dirty if the workdir index is modified, there
|
394
|
+
* are modified files in the workdir or if there are untracked files in the
|
395
|
+
* workdir.
|
396
|
+
*/
|
397
|
+
static VALUE rb_git_submodule_status_dirty_workdir(VALUE self)
|
398
|
+
{
|
399
|
+
RB_GIT_SUBMODULE_STATUS_CHECK(GIT_SUBMODULE_STATUS_IS_WD_DIRTY)
|
400
|
+
}
|
401
|
+
|
402
|
+
/*
|
403
|
+
* call-seq:
|
404
|
+
* submodule.add_to_index([options]) -> submodule
|
405
|
+
*
|
406
|
+
* Add current submodule +HEAD+ commit to the index of superproject.
|
407
|
+
*
|
408
|
+
* The following options can be passed in the +options+ Hash:
|
409
|
+
*
|
410
|
+
* :write_index ::
|
411
|
+
* (default +true+) If this should immediately write the index file.
|
412
|
+
* If passed as +false+, Rugged::Repository#index can be used to explicitly
|
413
|
+
* call Rugged::Index#write to save the change.
|
414
|
+
*/
|
415
|
+
static VALUE rb_git_submodule_add_to_index(int argc, VALUE *argv, VALUE self)
|
416
|
+
{
|
417
|
+
git_submodule *submodule;
|
418
|
+
VALUE rb_options;
|
419
|
+
int write_index = 1;
|
420
|
+
|
421
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
422
|
+
|
423
|
+
rb_scan_args(argc, argv, ":", &rb_options);
|
424
|
+
|
425
|
+
if (!NIL_P(rb_options)) {
|
426
|
+
VALUE rb_val;
|
427
|
+
|
428
|
+
rb_val = rb_hash_aref(rb_options, CSTR2SYM("write_index"));
|
429
|
+
write_index = (rb_val != Qfalse);
|
430
|
+
}
|
431
|
+
|
432
|
+
rugged_exception_check(
|
433
|
+
git_submodule_add_to_index(submodule, write_index)
|
434
|
+
);
|
435
|
+
|
436
|
+
return self;
|
437
|
+
}
|
438
|
+
|
439
|
+
/*
|
440
|
+
* call-seq:
|
441
|
+
* submodule.reload -> submodule
|
442
|
+
*
|
443
|
+
* Reread submodule info from config, index, and +HEAD+.
|
444
|
+
*
|
445
|
+
* Call this to reread cached submodule information for this submodule if
|
446
|
+
* there is reason to believe that it has changed.
|
447
|
+
*/
|
448
|
+
static VALUE rb_git_submodule_reload(VALUE self)
|
449
|
+
{
|
450
|
+
git_submodule *submodule;
|
451
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
452
|
+
|
453
|
+
rugged_exception_check(
|
454
|
+
git_submodule_reload(submodule, 1)
|
455
|
+
);
|
456
|
+
|
457
|
+
return self;
|
458
|
+
}
|
459
|
+
|
460
|
+
/*
|
461
|
+
* call-seq:
|
462
|
+
* submodule.sync -> submodule
|
463
|
+
*
|
464
|
+
* Copy submodule remote info into submodule repository.
|
465
|
+
*
|
466
|
+
* This copies the information about the submodules URL into the checked out
|
467
|
+
* submodule config, acting like <tt>"git submodule sync"</tt>. This is useful
|
468
|
+
* if the URL for the submodule was altered (by a manual change, or a fetch of
|
469
|
+
* upstream changes) and the local repository needs to be updated.
|
470
|
+
*/
|
471
|
+
static VALUE rb_git_submodule_sync(VALUE self)
|
472
|
+
{
|
473
|
+
git_submodule *submodule;
|
474
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
475
|
+
|
476
|
+
rugged_exception_check(
|
477
|
+
git_submodule_sync(submodule)
|
478
|
+
);
|
479
|
+
|
480
|
+
return self;
|
481
|
+
}
|
482
|
+
|
483
|
+
/*
|
484
|
+
* call-seq:
|
485
|
+
* submodule.init([options]) -> submodule
|
486
|
+
*
|
487
|
+
* Copy submodule info into +.git/config+ file.
|
488
|
+
*
|
489
|
+
* Just like <tt>"git submodule init"</tt>, this copies information about the
|
490
|
+
* submodule into +.git/config+.
|
491
|
+
*
|
492
|
+
* The following options can be passed in the +options+ Hash:
|
493
|
+
*
|
494
|
+
* :overwrite ::
|
495
|
+
* (defaults to +false+) - By default, existing entries
|
496
|
+
* will not be overwritten, but setting this to +true+ forces them to be
|
497
|
+
* updated.
|
498
|
+
*/
|
499
|
+
static VALUE rb_git_submodule_init(int argc, VALUE *argv, VALUE self)
|
500
|
+
{
|
501
|
+
git_submodule *submodule;
|
502
|
+
VALUE rb_options;
|
503
|
+
int overwrite = 0;
|
504
|
+
|
505
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
506
|
+
|
507
|
+
rb_scan_args(argc, argv, ":", &rb_options);
|
508
|
+
|
509
|
+
if (!NIL_P(rb_options)) {
|
510
|
+
VALUE rb_val;
|
511
|
+
|
512
|
+
rb_val = rb_hash_aref(rb_options, CSTR2SYM("overwrite"));
|
513
|
+
overwrite = RTEST(rb_val);
|
514
|
+
}
|
515
|
+
|
516
|
+
rugged_exception_check(
|
517
|
+
git_submodule_init(submodule, overwrite)
|
518
|
+
);
|
519
|
+
|
520
|
+
return self;
|
521
|
+
}
|
522
|
+
|
523
|
+
/*
|
524
|
+
* call-seq:
|
525
|
+
* submodule.name -> string
|
526
|
+
*
|
527
|
+
* Returns the name of the submodule.
|
528
|
+
*/
|
529
|
+
static VALUE rb_git_submodule_name(VALUE self)
|
530
|
+
{
|
531
|
+
git_submodule *submodule;
|
532
|
+
const char *name;
|
533
|
+
|
534
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
535
|
+
|
536
|
+
name = git_submodule_name(submodule);
|
537
|
+
|
538
|
+
return rb_str_new_utf8(name);
|
539
|
+
}
|
540
|
+
|
541
|
+
/*
|
542
|
+
* call-seq:
|
543
|
+
* submodule.url -> string or nil
|
544
|
+
*
|
545
|
+
* Returns the URL of the submodule.
|
546
|
+
*/
|
547
|
+
static VALUE rb_git_submodule_url(VALUE self)
|
548
|
+
{
|
549
|
+
|
550
|
+
git_submodule *submodule;
|
551
|
+
const char *url;
|
552
|
+
|
553
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
554
|
+
|
555
|
+
url = git_submodule_url(submodule);
|
556
|
+
|
557
|
+
return url ? rb_str_new_utf8(url) : Qnil;
|
558
|
+
}
|
559
|
+
|
560
|
+
/*
|
561
|
+
* call-seq:
|
562
|
+
* submodule.path -> string
|
563
|
+
*
|
564
|
+
* Returns the path of the submodule.
|
565
|
+
*
|
566
|
+
* The +path+ is almost always the same as the #name,
|
567
|
+
* but the two are actually not required to match.
|
568
|
+
*/
|
569
|
+
static VALUE rb_git_submodule_path(VALUE self)
|
570
|
+
{
|
571
|
+
git_submodule *submodule;
|
572
|
+
const char *path;
|
573
|
+
|
574
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
575
|
+
|
576
|
+
path = git_submodule_path(submodule);
|
577
|
+
|
578
|
+
return rb_str_new_utf8(path);
|
579
|
+
}
|
580
|
+
|
581
|
+
#define RB_GIT_OID_GETTER(_klass, _attribute) \
|
582
|
+
git_##_klass *object; \
|
583
|
+
const git_oid * oid; \
|
584
|
+
Data_Get_Struct(self, git_##_klass, object); \
|
585
|
+
oid = git_##_klass##_##_attribute(object); \
|
586
|
+
return oid ? rugged_create_oid(oid) : Qnil; \
|
587
|
+
|
588
|
+
/*
|
589
|
+
* call-seq:
|
590
|
+
* submodule.head_oid -> string or nil
|
591
|
+
*
|
592
|
+
* Returns the OID for the submodule in the current +HEAD+ tree or +nil+
|
593
|
+
* if the submodule is not in the +HEAD+.
|
594
|
+
*/
|
595
|
+
static VALUE rb_git_submodule_head_id(VALUE self)
|
596
|
+
{
|
597
|
+
RB_GIT_OID_GETTER(submodule, head_id);
|
598
|
+
}
|
599
|
+
|
600
|
+
/*
|
601
|
+
* call-seq:
|
602
|
+
* submodule.index_oid -> string or nil
|
603
|
+
*
|
604
|
+
* Returns the OID for the submodule in the index or +nil+ if the submodule
|
605
|
+
* is not in the index.
|
606
|
+
*/
|
607
|
+
static VALUE rb_git_submodule_index_id(VALUE self)
|
608
|
+
{
|
609
|
+
RB_GIT_OID_GETTER(submodule, index_id);
|
610
|
+
}
|
611
|
+
|
612
|
+
/*
|
613
|
+
* call-seq:
|
614
|
+
* submodule.workdir_oid -> string or nil
|
615
|
+
*
|
616
|
+
* Returns the OID for the submodule in the current working directory or
|
617
|
+
* +nil+ of the submodule is not checked out.
|
618
|
+
*
|
619
|
+
* This returns the OID that corresponds to looking up +HEAD+ in the checked
|
620
|
+
* out submodule. If there are pending changes in the index or anything
|
621
|
+
* else, this won't notice that. #status can be called for a more complete
|
622
|
+
* picture about the state of the working directory.
|
623
|
+
*/
|
624
|
+
static VALUE rb_git_submodule_wd_id(VALUE self)
|
625
|
+
{
|
626
|
+
RB_GIT_OID_GETTER(submodule, wd_id);
|
627
|
+
}
|
628
|
+
|
629
|
+
/*
|
630
|
+
* call-seq:
|
631
|
+
* submodule.fetch_recurse_submodules? -> true or false
|
632
|
+
*
|
633
|
+
* Returns the +fetchRecurseSubmodules+ rule for a submodule.
|
634
|
+
*
|
635
|
+
* This accesses the <tt>submodule.<name>.fetchRecurseSubmodules</tt> value
|
636
|
+
* for the submodule that controls fetching behavior for the submodule.
|
637
|
+
*
|
638
|
+
* Note that at this time, +Rugged+ does not honor this setting and the fetch
|
639
|
+
* functionality currently ignores submodules.
|
640
|
+
*
|
641
|
+
*/
|
642
|
+
static VALUE rb_git_submodule_fetch_recurse_submodules(VALUE self)
|
643
|
+
{
|
644
|
+
git_submodule *submodule;
|
645
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
646
|
+
|
647
|
+
return git_submodule_fetch_recurse_submodules(submodule) ? Qtrue : Qfalse;
|
648
|
+
}
|
649
|
+
|
650
|
+
static VALUE rb_git_subm_ignore_rule_fromC(git_submodule_ignore_t rule)
|
651
|
+
{
|
652
|
+
switch(rule) {
|
653
|
+
case GIT_SUBMODULE_IGNORE_NONE:
|
654
|
+
return ID2SYM(id_ignore_none);
|
655
|
+
case GIT_SUBMODULE_IGNORE_UNTRACKED:
|
656
|
+
return ID2SYM(id_ignore_untracked);
|
657
|
+
case GIT_SUBMODULE_IGNORE_DIRTY:
|
658
|
+
return ID2SYM(id_ignore_dirty);
|
659
|
+
case GIT_SUBMODULE_IGNORE_ALL:
|
660
|
+
return ID2SYM(id_ignore_all);
|
661
|
+
default:
|
662
|
+
return CSTR2SYM("unknown");
|
663
|
+
}
|
664
|
+
}
|
665
|
+
|
666
|
+
/*
|
667
|
+
* call-seq:
|
668
|
+
* submodule.ignore_rule -> symbol
|
669
|
+
*
|
670
|
+
* Returns the ignore rule for a submodule.
|
671
|
+
*
|
672
|
+
* There are four ignore values:
|
673
|
+
*
|
674
|
+
* :none (default)::
|
675
|
+
* will consider any change to the contents of the submodule from
|
676
|
+
* a clean checkout to be dirty, including the addition of untracked files.
|
677
|
+
* :untracked ::
|
678
|
+
* examines the contents of the working tree but untracked files will not
|
679
|
+
* count as making the submodule dirty.
|
680
|
+
* :dirty ::
|
681
|
+
* means to only check if the +HEAD+ of the submodule has moved for status.
|
682
|
+
* This is fast since it does not need to scan the working tree
|
683
|
+
* of the submodule at all.
|
684
|
+
* :all ::
|
685
|
+
* means not to open the submodule repository. The working directory will be
|
686
|
+
* considered clean so long as there is a checked out version present.
|
687
|
+
*
|
688
|
+
* See #status on how ignore rules reflect the returned status info
|
689
|
+
* for a submodule.
|
690
|
+
*/
|
691
|
+
static VALUE rb_git_submodule_ignore_rule(VALUE self)
|
692
|
+
{
|
693
|
+
git_submodule *submodule;
|
694
|
+
git_submodule_ignore_t ignore;
|
695
|
+
|
696
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
697
|
+
ignore = git_submodule_ignore(submodule);
|
698
|
+
|
699
|
+
return rb_git_subm_ignore_rule_fromC(ignore);
|
700
|
+
}
|
701
|
+
|
702
|
+
static VALUE rb_git_subm_update_rule_fromC(git_submodule_update_t rule)
|
703
|
+
{
|
704
|
+
switch(rule) {
|
705
|
+
case GIT_SUBMODULE_UPDATE_CHECKOUT:
|
706
|
+
return ID2SYM(id_update_checkout);
|
707
|
+
case GIT_SUBMODULE_UPDATE_REBASE:
|
708
|
+
return ID2SYM(id_update_rebase);
|
709
|
+
case GIT_SUBMODULE_UPDATE_MERGE:
|
710
|
+
return ID2SYM(id_update_merge);
|
711
|
+
case GIT_SUBMODULE_UPDATE_NONE:
|
712
|
+
return ID2SYM(id_update_none);
|
713
|
+
default:
|
714
|
+
return CSTR2SYM("unknown");
|
715
|
+
}
|
716
|
+
}
|
717
|
+
|
718
|
+
/*
|
719
|
+
* call-seq:
|
720
|
+
* submodule.update_rule -> symbol
|
721
|
+
*
|
722
|
+
* Returns the update rule for a submodule.
|
723
|
+
*
|
724
|
+
* There are four update_rule values:
|
725
|
+
*
|
726
|
+
* :checkout (default)::
|
727
|
+
* the new commit specified in the superproject will be checked out in the
|
728
|
+
* submodule on a detached +HEAD+.
|
729
|
+
* :rebase ::
|
730
|
+
* the current branch of the submodule will be rebased onto the commit
|
731
|
+
* specified in the superproject.
|
732
|
+
* :merge ::
|
733
|
+
* the commit specified in the superproject will be merged into the current
|
734
|
+
* branch of the submodule.
|
735
|
+
* :none ::
|
736
|
+
* the submodule will not be updated
|
737
|
+
*/
|
738
|
+
static VALUE rb_git_submodule_update_rule(VALUE self)
|
739
|
+
{
|
740
|
+
git_submodule *submodule;
|
741
|
+
git_submodule_update_t update;
|
742
|
+
|
743
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
744
|
+
update = git_submodule_update_strategy(submodule);
|
745
|
+
|
746
|
+
return rb_git_subm_update_rule_fromC(update);
|
747
|
+
}
|
748
|
+
|
749
|
+
/*
|
750
|
+
* call-seq:
|
751
|
+
* submodule.repository -> repository
|
752
|
+
*
|
753
|
+
* Returns the +repository+ for the submodule.
|
754
|
+
*
|
755
|
+
* The returned +repository+ is a newly opened Rugged::Repository object.
|
756
|
+
* This will only work if the submodule is checked out into the working
|
757
|
+
* directory.
|
758
|
+
*/
|
759
|
+
static VALUE rb_git_submodule_repository(VALUE self)
|
760
|
+
{
|
761
|
+
git_submodule *submodule;
|
762
|
+
git_repository *repo;
|
763
|
+
|
764
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
765
|
+
|
766
|
+
rugged_exception_check(
|
767
|
+
git_submodule_open(&repo, submodule)
|
768
|
+
);
|
769
|
+
|
770
|
+
return rugged_repo_new(rb_cRuggedRepo, repo);
|
771
|
+
}
|
772
|
+
|
773
|
+
/*
|
774
|
+
* call-seq:
|
775
|
+
* submodule.finalize_add -> submodule
|
776
|
+
*
|
777
|
+
* Resolve the setup of a new submodule.
|
778
|
+
*
|
779
|
+
* This should be called on a submodule once
|
780
|
+
* Rugged::SubmoduleCollection#setup_add is finished and the sumodule repo is
|
781
|
+
* cloned.
|
782
|
+
*
|
783
|
+
* This adds the +.gitmodules+ file and the newly cloned submodule to the index
|
784
|
+
* to be ready to be committed (but doesn't actually do the commit).
|
785
|
+
*/
|
786
|
+
static VALUE rb_git_submodule_finalize_add(VALUE self)
|
787
|
+
{
|
788
|
+
git_submodule *submodule;
|
789
|
+
Data_Get_Struct(self, git_submodule, submodule);
|
790
|
+
|
791
|
+
rugged_exception_check(
|
792
|
+
git_submodule_add_finalize(submodule)
|
793
|
+
);
|
794
|
+
|
795
|
+
return self;
|
796
|
+
}
|
797
|
+
|
798
|
+
void Init_rugged_submodule(void)
|
799
|
+
{
|
800
|
+
init_status_list();
|
801
|
+
id_ignore_none = rb_intern("none");
|
802
|
+
id_ignore_dirty = rb_intern("dirty");
|
803
|
+
id_ignore_untracked = rb_intern("untracked");
|
804
|
+
id_ignore_all = rb_intern("all");
|
805
|
+
|
806
|
+
id_update_checkout = rb_intern("checkout");
|
807
|
+
id_update_rebase = rb_intern("rebase");
|
808
|
+
id_update_merge = rb_intern("merge");
|
809
|
+
id_update_none = rb_intern("none");
|
810
|
+
|
811
|
+
rb_cRuggedSubmodule = rb_define_class_under(rb_mRugged, "Submodule", rb_cObject);
|
812
|
+
|
813
|
+
rb_define_method(rb_cRuggedSubmodule, "finalize_add", rb_git_submodule_finalize_add, 0);
|
814
|
+
|
815
|
+
rb_define_method(rb_cRuggedSubmodule, "name", rb_git_submodule_name, 0);
|
816
|
+
rb_define_method(rb_cRuggedSubmodule, "url", rb_git_submodule_url, 0);
|
817
|
+
rb_define_method(rb_cRuggedSubmodule, "path", rb_git_submodule_path, 0);
|
818
|
+
rb_define_method(rb_cRuggedSubmodule, "fetch_recurse_submodules?", rb_git_submodule_fetch_recurse_submodules, 0);
|
819
|
+
|
820
|
+
rb_define_method(rb_cRuggedSubmodule, "ignore_rule", rb_git_submodule_ignore_rule, 0);
|
821
|
+
rb_define_method(rb_cRuggedSubmodule, "update_rule", rb_git_submodule_update_rule, 0);
|
822
|
+
|
823
|
+
rb_define_method(rb_cRuggedSubmodule, "head_oid", rb_git_submodule_head_id, 0);
|
824
|
+
rb_define_method(rb_cRuggedSubmodule, "index_oid", rb_git_submodule_index_id, 0);
|
825
|
+
rb_define_method(rb_cRuggedSubmodule, "workdir_oid", rb_git_submodule_wd_id, 0);
|
826
|
+
|
827
|
+
rb_define_method(rb_cRuggedSubmodule, "status", rb_git_submodule_status, 0);
|
828
|
+
rb_define_method(rb_cRuggedSubmodule, "in_head?", rb_git_submodule_status_in_head, 0);
|
829
|
+
rb_define_method(rb_cRuggedSubmodule, "in_index?", rb_git_submodule_status_in_index, 0);
|
830
|
+
rb_define_method(rb_cRuggedSubmodule, "in_config?", rb_git_submodule_status_in_config, 0);
|
831
|
+
rb_define_method(rb_cRuggedSubmodule, "in_workdir?", rb_git_submodule_status_in_workdir, 0);
|
832
|
+
rb_define_method(rb_cRuggedSubmodule, "added_to_index?", rb_git_submodule_status_added_to_index, 0);
|
833
|
+
rb_define_method(rb_cRuggedSubmodule, "deleted_from_index?", rb_git_submodule_status_deleted_from_index, 0);
|
834
|
+
rb_define_method(rb_cRuggedSubmodule, "modified_in_index?", rb_git_submodule_status_modified_in_index, 0);
|
835
|
+
rb_define_method(rb_cRuggedSubmodule, "uninitialized?", rb_git_submodule_status_uninitialized, 0);
|
836
|
+
rb_define_method(rb_cRuggedSubmodule, "added_to_workdir?", rb_git_submodule_status_added_to_workdir, 0);
|
837
|
+
rb_define_method(rb_cRuggedSubmodule, "deleted_from_workdir?", rb_git_submodule_status_deleted_from_workdir, 0);
|
838
|
+
rb_define_method(rb_cRuggedSubmodule, "modified_in_workdir?", rb_git_submodule_status_modified_in_workdir, 0);
|
839
|
+
rb_define_method(rb_cRuggedSubmodule, "dirty_workdir_index?", rb_git_submodule_status_dirty_workdir_index, 0);
|
840
|
+
rb_define_method(rb_cRuggedSubmodule, "modified_files_in_workdir?", rb_git_submodule_status_modified_files_in_workdir, 0);
|
841
|
+
rb_define_method(rb_cRuggedSubmodule, "untracked_files_in_workdir?", rb_git_submodule_status_untracked_files_in_workdir, 0);
|
842
|
+
|
843
|
+
rb_define_method(rb_cRuggedSubmodule, "unmodified?", rb_git_submodule_status_unmodified, 0);
|
844
|
+
rb_define_method(rb_cRuggedSubmodule, "dirty_workdir?", rb_git_submodule_status_dirty_workdir, 0);
|
845
|
+
|
846
|
+
rb_define_method(rb_cRuggedSubmodule, "repository", rb_git_submodule_repository, 0);
|
847
|
+
|
848
|
+
rb_define_method(rb_cRuggedSubmodule, "add_to_index", rb_git_submodule_add_to_index, -1);
|
849
|
+
rb_define_method(rb_cRuggedSubmodule, "reload", rb_git_submodule_reload, 0);
|
850
|
+
rb_define_method(rb_cRuggedSubmodule, "sync", rb_git_submodule_sync, 0);
|
851
|
+
rb_define_method(rb_cRuggedSubmodule, "init", rb_git_submodule_init, -1);
|
852
|
+
}
|