#include "commit.h"
#include "revision.h"
#include "run-command.h"
+#include "diffcore.h"
static int add_submodule_odb(const char *path)
{
struct strbuf objects_directory = STRBUF_INIT;
struct alternate_object_database *alt_odb;
int ret = 0;
+ const char *git_dir;
- strbuf_addf(&objects_directory, "%s/.git/objects/", path);
+ strbuf_addf(&objects_directory, "%s/.git", path);
+ git_dir = read_gitfile_gently(objects_directory.buf);
+ if (git_dir) {
+ strbuf_reset(&objects_directory);
+ strbuf_addstr(&objects_directory, git_dir);
+ }
+ strbuf_addstr(&objects_directory, "/objects/");
if (!is_directory(objects_directory.buf)) {
ret = -1;
goto done;
message = "(revision walker failed)";
}
+ if (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
+ fprintf(f, "Submodule %s contains untracked content\n", path);
+ if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
+ fprintf(f, "Submodule %s contains modified content\n", path);
+
+ if (!hashcmp(one, two)) {
+ strbuf_release(&sb);
+ return;
+ }
+
strbuf_addf(&sb, "Submodule %s %s..", path,
find_unique_abbrev(one, DEFAULT_ABBREV));
if (!fast_backward && !fast_forward)
strbuf_addch(&sb, '.');
strbuf_addf(&sb, "%s", find_unique_abbrev(two, DEFAULT_ABBREV));
- if (dirty_submodule)
- strbuf_add(&sb, "-dirty", 6);
if (message)
strbuf_addf(&sb, " %s\n", message);
else
strbuf_release(&sb);
}
-int is_submodule_modified(const char *path)
+unsigned is_submodule_modified(const char *path, int ignore_untracked)
{
- int len;
+ ssize_t len;
struct child_process cp;
const char *argv[] = {
"status",
"--porcelain",
NULL,
+ NULL,
};
- char *env[4];
struct strbuf buf = STRBUF_INIT;
-
- strbuf_addf(&buf, "%s/.git/", path);
- if (!is_directory(buf.buf)) {
+ unsigned dirty_submodule = 0;
+ const char *line, *next_line;
+ const char *git_dir;
+
+ strbuf_addf(&buf, "%s/.git", path);
+ git_dir = read_gitfile_gently(buf.buf);
+ if (!git_dir)
+ git_dir = buf.buf;
+ if (!is_directory(git_dir)) {
strbuf_release(&buf);
/* The submodule is not checked out, so it is not modified */
return 0;
}
strbuf_reset(&buf);
- strbuf_addf(&buf, "GIT_WORK_TREE=%s", path);
- env[0] = strbuf_detach(&buf, NULL);
- strbuf_addf(&buf, "GIT_DIR=%s/.git", path);
- env[1] = strbuf_detach(&buf, NULL);
- strbuf_addf(&buf, "GIT_INDEX_FILE");
- env[2] = strbuf_detach(&buf, NULL);
- env[3] = NULL;
+ if (ignore_untracked)
+ argv[2] = "-uno";
memset(&cp, 0, sizeof(cp));
cp.argv = argv;
- cp.env = (const char *const *)env;
+ cp.env = local_repo_env;
cp.git_cmd = 1;
cp.no_stdin = 1;
cp.out = -1;
+ cp.dir = path;
if (start_command(&cp))
die("Could not run git status --porcelain");
len = strbuf_read(&buf, cp.out, 1024);
+ line = buf.buf;
+ while (len > 2) {
+ if ((line[0] == '?') && (line[1] == '?')) {
+ dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
+ if (dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
+ break;
+ } else {
+ dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
+ if (ignore_untracked ||
+ (dirty_submodule & DIRTY_SUBMODULE_UNTRACKED))
+ break;
+ }
+ next_line = strchr(line, '\n');
+ if (!next_line)
+ break;
+ next_line++;
+ len -= (next_line - line);
+ line = next_line;
+ }
close(cp.out);
if (finish_command(&cp))
die("git status --porcelain failed");
- free(env[0]);
- free(env[1]);
- free(env[2]);
strbuf_release(&buf);
- return len != 0;
+ return dirty_submodule;
}