We don't want vng executable to be placed inside Vng.app/Contents/MacOS on Mac OS X.
[vng.git] / Add.cpp
blobb187a1d88e51b7af98c232bd8c6a0645fb0e83b6
1 /*
2 * This file is part of the vng project
3 * Copyright (C) 2008 Thomas Zander <tzander@trolltech.com>
4 * Copyright (C) 2002-2004 David Roundy
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "Add.h"
21 #include "CommandLineParser.h"
22 #include "Logger.h"
23 #include "GitRunner.h"
24 #include "Vng.h"
26 #include <QFileInfo>
27 #include <QProcess>
29 static const CommandLineOption options[] = {
30 // TODO :)
31 //{"--boring", "don't skip boring files"},
32 //{"--umask <UMASK>", "specify umask to use when writing."},
33 CommandLineLastOption
36 Add::Add()
37 : AbstractCommand("add")
39 CommandLineParser::addOptionDefinitions(options);
40 CommandLineParser::setArgumentDefinition("add <FILE or DIRECTORY>" );
43 AbstractCommand::ReturnCodes Add::run()
45 if (! checkInRepository())
46 return NotInRepo;
48 foreach(QString arg, rebasedArguments()) {
49 QFileInfo path(arg);
50 if (path.exists()) {
51 if (path.isFile() || path.isDir()) {
52 QProcess checker;
53 QStringList arguments;
54 arguments << "ls-files" << path.filePath();
55 GitRunner runner(checker, arguments);
56 ReturnCodes rc = runner.start(GitRunner::WaitForStandardOutput);
57 if (rc != Ok)
58 return rc;
59 bool shouldAdd = true;
60 char buf[1024];
61 while(true) {
62 qint64 lineLength = Vng::readLine(&checker, buf, sizeof(buf));
63 if (lineLength == -1)
64 break;
65 shouldAdd = false; // lets assume here that the script just doesn't print anything if its not added yet.
66 break;
68 if (! shouldAdd) {
69 Logger::info() << "Not adding file, already in the repository: `" << path.filePath() << "'\n";
70 checker.waitForFinished();
71 continue;
73 Logger::warn() << "Adding '" << path.filePath() << "'" << endl;
74 QProcess git;
75 arguments.clear();
76 arguments << "update-index" << "--add" << path.filePath();
77 GitRunner runner2(git, arguments);
78 rc = runner2.start(GitRunner::WaitUntilFinished);
79 if (rc != Ok)
80 return rc;
82 else if (path.isSymLink())
83 Logger::info() << "Ignoring symbolic link '" << path.filePath() << "'" << endl;
84 else
85 Logger::info() << "Ignoring non-file object '" << path.filePath() << "'" << endl;
87 else
88 Logger::error() << "Can not add non existing' " << path.filePath() << "'" << endl;
90 return Ok;
93 QString Add::argumentDescription() const
95 return "<FILE or DIRECTORY>";
98 QString Add::commandDescription() const
100 return "Add needs to be called whenever you add a new file or directory to your\n"
101 "project. Of course, it also needs to be called when you first create the\n"
102 "project, to let vng know which files should be kept track of.\n";