Skip to content

Commit

Permalink
Merge pull request #880 from bes-internal/emptyrc
Browse files Browse the repository at this point in the history
Fix cli args; Ignore ~/.ungitrc with syntax error
  • Loading branch information
jung-kim authored Mar 22, 2017
2 parents 0c1cf19 + 6c2496a commit 352a7d2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
Use the following format for additions: ` - VERSION: [feature/patch (if applicable)] Short description of change. Links to relevant issues/PRs.`

- 1.1.11:
- Fix cli arguments [#871](https://github.com/FredrikNoren/ungit/pull/871)
- Stop if ~/.ungitrc contains syntax error
- Removed official support ini format of ~/.ungitrc, because internal API supports only JSON
- 1.1.10: Fix broken diff out in some cases when diff contains table. [#881](https://github.com/FredrikNoren/ungit/pull/881)
- 1.1.9: Fix around ubuntu's inability to cache promises. [#877](https://github.com/FredrikNoren/ungit/pull/878)
- 1.1.8:
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This will launch the server and open up a browser with the ui.

Configuring
---------
Put a configuration file called .ungitrc in your home directory (`/home/USERNAME` on \*nix, `C:/Users/USERNAME/` on windows). Can be in either json or ini format. See [source/config.js](source/config.js) for available options.
Put a configuration file called .ungitrc in your home directory (`/home/USERNAME` on \*nix, `C:/Users/USERNAME/` on windows). Configuration file must be in json format. See [source/config.js](source/config.js) for available options.

You can also override configuration variables at launch by specifying them as command line arguments; `ungit --port=8080`. To disable boolean features use --no: `ungit --no-autoFetch`.

Expand All @@ -57,8 +57,6 @@ Example of `~/.ungitrc` configuration file to change default port and enable bug
}
```

Ungit uses [rc](https://github.com/dominictarr/rc) for configuration, which in turn uses [yargs](https://github.com/yargs/yargs) for command line arguments. See corresponding documentations for more details.

External Merge Tools
--------------------
If you have your own merge tool that you would like to use, such as Kaleidoscope or p4merge, you can configure ungit to use it. See [MERGETOOL.md](MERGETOOL.md).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ungit",
"author": "Fredrik Norén <fredrik.jw.noren@gmail.com>",
"description": "Git made easy",
"version": "1.1.10",
"version": "1.1.11",
"ungitPluginApiVersion": "0.2.0",
"scripts": {
"start": "node ./bin/ungit",
Expand Down
29 changes: 22 additions & 7 deletions source/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ let argv = yargs
.describe('ungitVersionCheckOverride', 'Ignore check for older version of ungit')
.describe('b', 'Launch a browser window with ungit when the ungit server is started. --no-b or --no-launchBrowser disables this')
.describe('cliconfigonly', 'Ignore the default configuration points and only use parameters sent on the command line')
.boolean('cliconfigonly')
.describe('port', 'The port ungit is exposed on')
.describe('urlBase', 'The base URL ungit will be accessible from')
.describe('rootPath', 'The root path ungit will be accessible from')
Expand Down Expand Up @@ -190,23 +191,37 @@ let argv = yargs
.describe('autoCheckoutOnBranchCreate', 'Auto checkout the created branch on creation')
.describe('alwaysLoadActiveBranch', 'Always load with active checkout branch')
.describe('numberOfNodesPerLoad', 'number of nodes to load for each git.log call')
.describe('mergeTool', 'the git merge tool to use when resolving conflicts');
.describe('mergeTool', 'the git merge tool to use when resolving conflicts')
// rc return additional options that must be ignored
.describe('config', false)
.describe('configs', false);

var argvConfig = argv.argv;

// If not triggered by test, then do strict option check
if (argv.$0.indexOf('mocha') === -1) {
if (argvConfig.$0.indexOf('mocha') === -1) {
argv = argv.strict();
}

// For testing, $0 is grunt. For credential-parser test, $0 is node
// When ungit is started normaly, $0 == ungit, and non-hyphenated options exists, show help and exit.
if (argv.$0 === 'ungit' && argv._ && argv._.length > 0) {
if (argvConfig.$0.indexOf('ungit') > -1 && argvConfig._ && argvConfig._.length > 0) {
yargs.showHelp();
process.exit(0);
} else if (argv.cliconfigonly) {
module.exports = argv.default(defaultConfig).argv;
} else {
module.exports = rc('ungit', argv.default(defaultConfig).argv);
}

var rcConfig = {};
if (!argvConfig.cliconfigonly) {
try {
rcConfig = rc('ungit');
} catch (err) {
winston.error(`Stop at reading ~/.ungitrc because ${err}`);
process.exit(0);
}
}

module.exports = argv.default(defaultConfig).default(rcConfig).argv;

module.exports.homedir = homedir;

let currentRootPath = module.exports.rootPath;
Expand Down
13 changes: 8 additions & 5 deletions source/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,14 @@ app.get('/api/gitversion', (req, res) => {
const userConfigPath = path.join(config.homedir, '.ungitrc');
const readUserConfig = () => {
return fs.isExists(userConfigPath).then((hasConfig) => {
if (!hasConfig) return {};
return fs.readFileAsync(userConfigPath, { encoding: 'utf8' }).then((content) => {
return JSON.parse(content.toString());
});
});
if (!hasConfig) return {};
return fs.readFileAsync(userConfigPath, { encoding: 'utf8' })
.then((content) => { return JSON.parse(content.toString()); })
.catch((err) => {
winston.error(`Stop at reading ~/.ungitrc because ${err}`);
process.exit(0);
});
});
}
const writeUserConfig = (configContent) => {
return fs.writeFileAsync(userConfigPath, JSON.stringify(configContent, undefined, 2));
Expand Down

0 comments on commit 352a7d2

Please sign in to comment.